🪸Different ways to use print() in Python🐍

Photo by Jexo on Unsplash

🪸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 :

  1. Simple Print:

     print("Hello, World!")
    
  2. Print with Variables:

     name = "John"
     age = 25
     print("Name:", name, "Age:", age)
    
  3. Formatted String Literal (f-string):

     name = "Alice"
     age = 30
     print(f"Name: {name}, Age: {age}")
    
  4. String Concatenation:

     name = "Bob"
     age = 22
     print("Name: " + name + ", Age: " + str(age))
    
  5. Multiple Arguments in print:

     name = "Charlie"
     age = 28
     print("Name:", name, end=", ")
     print("Age:", age)
    
  6. Using format method: name = "Eve" age = 35 print("Name: {}, Age: {}".format(name, age))

  7. Using join with a Separator:

     codefruits = ["apple", "banana", "orange"]
     print(", ".join(fruits))
    
  8. Printing on the Same Line:

     print("Hello", end=" ")
     print("World!")