🪸Different ways to use print() in Python🐍
There are different ways to use print() in Python and you should use that best suits you😎
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!")