How do I insert a variable into a string in Python?

 If you want to insert a variable into a string in python

 there are several methods to insert a variable into a string.

  1. Concatenation Method.
  2. format method
  3. % operator
  4. Concatenation Method.

var = “shubham”

print(“Hello” + var + “welcome to my tutorial”)

2. format specifier

var1 = “shubham”

age = 24

var2 = “Hello {} you are {} years old”.format(var1,age)

print(var2)

3. % operator

var = “shubham”

var2 = “hello %s welcome back”%var

print(var2)

I hope it helps you.

Comments

Popular posts from this blog

proassignment help backlink data index 41

programming shark backink data index 31

Programming shark backlink data index 67