Detailed explanation on the use of str and repr in Python

黄舟
Release: 2017-08-20 10:16:23
Original
1397 people have browsed it

This article mainly introduces the relevant information on the detailed explanation of str and repr in the Python basic tutorial, mainly explaining the differences between them. Through this article, I hope to help everyone understand this part of the content. You can refer to it if you need it. Next

Detailed explanation of Python str and repr

str can convert the value into a reasonable string form so that users can understand it;

repr will be in legal Python Express values ​​in the form of expressions.

For example:


# str输出用户通常习惯的格式,repr输出系统存储格式
>>> print str("Hello World")
Hello World
>>> print repr("Hello World")
'Hello World'
>>> print str(10000L)
10000
>>> print repr(10000L)
10000L
>>>
Copy after login

Note that str represents a type, that is, a string; repr is a function.

The above is the detailed content of Detailed explanation on the use of str and repr 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!