Home > Backend Development > Python Tutorial > What are the print output formats in python?

What are the print output formats in python?

coldplay.xixi
Release: 2020-10-23 11:12:20
Original
40268 people have browsed it

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.

What are the print output formats in python?

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!')
Copy after login

# For python, single quotes can also represent strings

name = 'Tom'
Copy after login

# Custom variables, weak types, Different from strong types such as C

year = 2018
Copy after login

# Automatically match the int type equivalent to C

print(year)
Copy after login

# Print the content of the variable

print(name)
print("Hello " + name)
Copy after login

# Strings can be connected to other types

print("I " + "love " + "you")
Copy after login

# You can use the plus sign to connect

print("I","love","you")
Copy after login

# Comma connection will automatically add spaces between the connection strings

print("I ""love ""you")
Copy after login

# You can also connect directly

print( "Hello {0}".format(name) )
Copy after login

# 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) )
Copy after login

# 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):
Copy after login

# for loop A kind of loop range [0:5), left closed and right open interval

    print(i)
Copy after login

# print() automatically wraps

    print(i, end='\n')
Copy after login

# 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template