|
发表于 2022-3-5 15:22:02
|
显示全部楼层
- """
- The repr() function returns the string representation of the value passed to eval function by default.
- For the custom class object, it returns a string enclosed in angle brackets that contains the name and address of the object by default.
- """
- # 范例:
- class A: pass # 类
- B = lambda x: x*x*x # 函数
- x = 123 # 整数
- y = "456" # 字符串
- a = str(x) # 将整数变成字符串
- b = repr(x) # 以字符串形式,返回对象 x,如上,无差别
- c = repr(y) # 以字符串形式,返回字符串(如:字符串 repr("banana") = "\'banana\'")
- d = repr(A) # 以字符串形式,返回对象类型
- e = repr(B) # 以字符串形式,返回内存地址
- f = eval(y) # 去引号
- print(a, b, c, d, e, f, sep = "\n")
- print()
- print(type(a), type(b), type(b), type(d), type(e), type(f), sep = "\n")
复制代码- 123
- 123
- '456'
- <class '__main__.A'>
- <function <lambda> at 0x0000023145BC3E20>
- 456
- <class 'str'>
- <class 'str'>
- <class 'str'>
- <class 'str'>
- <class 'str'>
- <class 'int'>
复制代码 |
|