Home  >  Article  >  Backend Development  >  Do you need to put quotes in python when outputting numbers?

Do you need to put quotes in python when outputting numbers?

anonymity
anonymityOriginal
2019-06-14 11:36:096816browse

Python has two ways to output values: expression statements and print() function.

The third way is to use the write() method of the file object. The standard output file can be referenced with sys.stdout.

Do you need to put quotes in python when outputting numbers?

#If you want the output to be more diverse, you can use the str.format() function to format the output value.

If you want to convert the output value into a string, you can use the repr() or str() function to achieve this.

str(): The function returns a user-readable expression.

repr(): Produce an expression that is readable by the interpreter.

Example:

a=3
print ("'%s'"%(a))  ##方法1  %s为格式化字符串,然后将a传递进去,就变成了'3'
print("'{}'".format(a))  ##方法2  format函数用于字符串的格式化,原理同上

The above is the detailed content of Do you need to put quotes in python when outputting numbers?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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