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