Home > Article > Backend Development > What are the print output formats in python?
The print output format in python is: 1. You can use plus sign connection [print("I " "love " "you")]; 2. Comma connection will automatically add spaces between the connection strings [print ("I", "love", "you")]; 3. It can also be connected directly.
The print output format in Python is:
In Python, "" and '' are exactly the same as print( "Hello World!")
# Directly print the string
print('Hello World!')
# For python, single quotes can also represent strings
name = 'Tom'
# Custom variables, weak types, Different from strong types such as C
year = 2018
# Automatically match the int type equivalent to C
print(year)
# Print the content of the variable
print(name) print("Hello " + name)
# Strings can be connected to other types
print("I " + "love " + "you")
# You can use the plus sign to connect
print("I","love","you")
# Comma connection will automatically add spaces between the connection strings
print("I ""love ""you")
# You can also connect directly
print( "Hello {0}".format(name) )
# Formatted output, {0} refers to the 0th element of the output, similarly {1} is the 1st element, {2} is the 2nd...
print( "I am %s, today is %d year"%(name, year) )
# Similar to C Format output, similarly %f is a floating point number...print( f"Today is {year}")
# f string, the element in {} is
for i in range(0,5):
# for loop A kind of loop range [0:5), left closed and right open interval
print(i)
# print() automatically wraps
print(i, end='\n')
# end='', there are two contents in the quotation marks The interval between them, plus end, will not wrap unless end='\n' is specified.
A large number of free learning recommendations, please visit python Tutorial
The above is the detailed content of What are the print output formats in python?. For more information, please follow other related articles on the PHP Chinese website!