. Advertisement .
..3..
. Advertisement .
..4..
Computers are mostly used to store information and extract information from it. Python is one of the most powerful programming languages. We can use Python to get computers to do most routine processes. This blog is all about how we can print String and Variable in Python.
How Can You Print String and Variable in Python?
1) Utilize concatenation
Utilizing concatenation, you can print a string or a variable. It is incredibly simple to use. So, without spending any time, let’s get started with the following example.
strWebsite = "ITtutoria"
numYear = 2022
print("My website is " + strWebsite + " and years is " + str(numYear))
Result:
My website is ITtutoria and years is 2022
2) Utilize %
Utilizing %, you can print a string or a variable. It is incredibly simple to use. So, without spending any time, let’s get started with the following example.
myWebsite = "ITtutoria"
yearNum = 2022
print("My website is %s and years is %d" %(myWebsite,yearNum))
Result:
My website is ITtutoria and years is 2022
3) Utilize commas
Utilizing commas, you can print a string or a variable. It is incredibly simple to use. So, without spending any time, let’s get started with the following example.
myAge = 39
print("My age is :",myAge)
Result:
My age is : 39
Conclusion
Printing String and Variable in Python is a confusing problem. We hope this blog has helped clear the air around how to do it. If you have more questions about this topic, please comment below. Thank you for reading; we are always excited when one of our posts can provide useful information on a topic like this!
Leave a comment