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