close

How To Python Print Variable

Hello guys. today i will teach you how to print a variable in python. In python you can print a single variable as well as multiple variable. There are different methods to print a variable. So lets learn about How To Python Print Variable.

How To Python Print Variable

  1. How To Python Print Variable

    print single variable If you want to print a single variable then use this method. Lets learn this by a below example: var1 = "Hello guys" print(var1) Output : Hello guys. print multiple variables. If you want to print a multiple variable then use this method. Lets learn this by a below example : var1 = "Hello guys" var2 = "how are you" print(var1,var2) Output : Hello guys how are you

  2. Python Print Variable

    Using comma character By using comma you can print a multiple variable. Lets learn this by a below example: var1 = 2 var2 = 'harry' var3 = 'carry' print("I have", var1, "bestfriends:", var2, "and", var3) Output : I have 2 bestfriends: harry and carry. Using % By using % you can print a multiple variable. Lets learn this by a below example: var1 = 1 var2 = "harry" print("I have only %d bestfriend and he is %s" %(var1,var2))Output : I have only 1 bestfriend and he is harry

Method 1 : print single variable

If you want to print a single variable then use this method. Lets learn this by a below example:

var1 = "Hello guys"
print(var1)

Output :

Hello guys

Method 2 : print multiple variables

If you want to print a multiple variable then use this method. Lets learn this by a below example :

var1 = "Hello guys"
var2 = "how are you"
print(var1,var2)

Output :

Hello guys how are you

Method 3 : Using comma character

By using comma you can print a multiple variable. Lets learn this by a below example:

var1 = 2
var2 = 'harry'
var3 = 'carry'
print("I have", var1, "bestfriends:", var2, "and", var3)

Output :

I have 2 bestfriends: harry and carry

Method 4 : Using %

By using % you can print a multiple variable. Lets learn this by a below example:

var1 = 1
var2 = "harry"
print("I have only %d bestfriend and he is %s" %(var1,var2))

Output :

I have only 1 bestfriend and he is harry

Method 5 : Using f-string

By using f-string you can print a multiple variable. Lets learn this by a below example:

var1= "How are you"
var2= "whts up"
print(f'Hello guys {var1} {var2}')

Output :

Hello guys How are you whts up

Thus with the help of these methods you can easily print variables. I hope you like it.

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment