Q:

how to print a variable in python

variable = "Hello World"
print(variable)
1
name = "Bob"
print(f"hello {name}!")
1
var = "Python printing is amazing!"
print(var)
3
print("If there was a birth every 7 seconds, there would be: {} births".format(births))
0
name = "Steven"

# Using f-strings
print(f"Hi, {name}!")

# Using format()
print("Hi, {}!".format(name))
0
>>> print("{:d} {:03d} {:>20f}".format(1, 2, 1.1))
1 002             1.100000
  ^^^
  0's padded to 2
0
>>> print("foo", "bar", "spam")
foo bar spam
0
str1 = "Hello World"
print(str1)
0
print("If there was a birth every 7 seconds, there would be: ", births, "births")
0

New to Communities?

Join the community