print string variable python code example
Example 1: how to print variables in a string python
name = "Steven"
print(f"Hi, {name}!")
print("Hi, {}!".format(name))
Example 2: python print string and variable
print "If there was a birth every 7 seconds, there would be: {} births".format(births)
Example 3: python print variable and string
foo = "seven"
print("She lives with " + foo + " small men")
Example 4: python print variable
var = "Python printing is amazing!"
print(var)
Example 5: print variable string python
>>> print("{:d} {:03d} {:>20f}".format(1, 2, 1.1))
1 002 1.100000
^^^
0's padded to 2