xxxxxxxxxx
var = 28
print(f"Your age: {var} years old")
xxxxxxxxxx
name = "Steven"
# Using f-strings
print(f"Hi, {name}!")
# Using format()
print("Hi, {}!".format(name))
xxxxxxxxxx
# 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
xxxxxxxxxx
>>> print("{:d} {:03d} {:>20f}".format(1, 2, 1.1))
1 002 1.100000
^^^
0's padded to 2
xxxxxxxxxx
x = input("Enter the first number: ")
y = input("Enter the second number: ")
z = int(x)+int(y)
#Just use a comma
print("The sum of the numbers you entered =",z)
xxxxxxxxxx
#How to print a variable the code below sets a variable to Hello, World!
variable = "Hello, World!"
#Use the print function to write out anything (the name variable after the print function is the name of the variable you want to print)
print(variable)
xxxxxxxxxx
#HOW TO PRINT A VARIABLE.
name = 'Wizard'
print(name)
#IT'LL PRINT THE VERY VARIABLE "name"