🪸Different ways to use print() in Python🐍
When I was new to coding, late in 2022's, I use only 2 or 3 types of print()...But now, I got to know so many new ways to use print()...
Do you want to know these methods ???
✌🏻Let's have a glimpse on these methods :
Simple Print:
print("Hello, World!")
Print with Variables:
name = "John" age = 25 print("Name:", name, "Age:", age)
Formatted String Literal (f-string):
name = "Alice" age = 30 print(f"Name: {name}, Age: {age}")
String Concatenation:
name = "Bob" age = 22 print("Name: " + name + ", Age: " + str(age))
Multiple Arguments in
print
:name = "Charlie" age = 28 print("Name:", name, end=", ") print("Age:", age)
Using
format
method: name = "Eve" age = 35 print("Name: {}, Age: {}".format(name, age))Using
join
with a Separator:codefruits = ["apple", "banana", "orange"] print(", ".join(fruits))
Printing on the Same Line:
print("Hello", end=" ") print("World!")
Subscribe to my newsletter
Read articles from Hitendra Kumar Dewangan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Hitendra Kumar Dewangan
Hitendra Kumar Dewangan
👋 Hi, I’m @HitenDewangan 👀 I enjoy coding, music, graphic designing and martial arts. 🧩 Intermediate coder in Python. 🪸 Learnt Fundamentals of C and Data Analysis with MS Excel. 🌱 I’m currently learning Web Development, and Data Science with Python(Panda). 💞️ I’m looking to collaborate on projects. 📫 How to reach me : Email: hitendewangan100j@gmail.com