python print variable

In this tutorial we will learn about to print variable in python. We can print two or three variable together also. We will learn this by different methods In python print variable have many methods. Lets learn it.

python print variable

Advertisements

Here i am giving you the different methods to print the variable in python. Lets see these methods:

  1. Use print
  2. Use comma
  3. Use %
  4. Use{}
  5. Use f-string

By using these method you will easily print a variable in python

  1. python print variable

    to print variable just Use print. By using print statement you can print variable.
    In python 3 you can print variable with the use of print statement in below example's way. you just have to write print and put the parenthesis and it will print it. print('Hello guys') Output : Hello guys

  2. print variable

    to print variable just Use comma. If you want to print two or three variable together than just put a comma in between of the different variable and print it. Thus this is also very easy and helpful. Lets see it. var1 = 123 var2 = 'And lets start to learn it' print(var1,var2) Output : 123 And lets start to learn it

Method 1 : Use print

Advertisements

By using print statement you can print variable.

In python 3 you can print variable with the use of print statement in below example’s way. you just have to write print and put the parenthesis and it will print it.

print('Hello guys')

Output :

Hello guys

Method 2: Use comma

Advertisements

If you want to print two or three variable together than just put a comma in between of the different variable and print it. Thus this is also very easy and helpful. Lets see it.

var1 = 123
var2 = 'And lets start to learn it'
print(var1,var2)

Output :

123 And lets start to learn it

Method 3: Use %

Advertisements

% is used for printing a variable in python. By using % you can print two variable together. Here i am using %d to print integer number and %s to print a string variable. Thus you can use different % to print different variable in python. Lets see this in below example:

var1 = 123
var2 = 'And lets start to learn it'
print("%d %s " %(var1,var2))

Output :

123 And lets start to learn it

Method 4: Use{}

Advertisements

By using {} you can easily print a variable. If you want to print to variable together than you can use this method. Lets learn this.

var1= 123
var2 = 'And lets start to learn it'
print("{} {}".format(var1,var2))

Output :

123 And lets start to learn it

Method 5: Use f-string

To print a variable you can use f-string. By using it you can easily print two variable together. Lets learn this by given below example:

var1= 123
var2 = 'And lets start to learn it'
print(f'{var1} {var2}')

Output :

123 And lets start to learn it

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment