Hello guys. How are you? I hope you all fine. In this tutorial we will learn about how to print String and Variable in Python. So without wasting time lets learn about of this.
How to print String and Variable in Python
print String and Variable in Python
To print String and Variable in Python You can print string and variable by using % . Its very easy to use. so lets about of this without wasting time by given below example.
name = "happy" age = 24 print("My name is %s and my age is %d" %(name,age))
Output :My name is happy and my age is 24
How to print String and Variable in Python
To print String and Variable in Python You can print string and variable by using commas . Its very easy to use. so lets about of this without wasting time by given below example.
rollnumber = 19 print("My roll number is :",rollnumber)
Output :My roll number is : 19
Method 1: Using %
You can print string and variable by using % . Its very easy to use. so lets about of this without wasting time by given below example.
name = "happy"
age = 24
print("My name is %s and my age is %d" %(name,age))
Output :
My name is happy and my age is 24
Method 2: Using commas
You can print string and variable by using commas . Its very easy to use. so lets about of this without wasting time by given below example.
rollnumber = 19
print("My roll number is :",rollnumber)
Output :
My roll number is : 19
Method 3: Using concatenation
You can print string and variable by using concatenation . Its very easy to use. so lets about of this without wasting time by given below example.
name = "Happy"
marks = 90
print("My name is " + name + " and i got " + str(marks) + " marks in physics")
Output :
My name is Happy and i got 90 marks in physics
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