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

anonymity
Release: 2019-06-14 11:36:09
Original
6849 people have browsed it

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函数用于字符串的格式化,原理同上
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!