Sean Sin
0
Q:

python print variable and string

print "If there was a birth every 7 seconds, there would be: {} births".format(births)
1
foo = "seven"

print("She lives with " + foo + " small men")
5
# This prints out "John is 23 years old."
name = "John"
age = 23
print("%s is %d years old." % (name, age))
# note: the letter is based on the datatype. %s = string, %d = decimal
0
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
print("If there was a birth every 7 seconds, there would be: ", births, "births")
0

New to Communities?

Join the community