中易网

python str函数怎么用

答案:2  悬赏:0  
解决时间 2021-01-16 09:55
  • 提问者网友:戎马万世
  • 2021-01-15 14:24
python str函数怎么用
最佳答案
  • 二级知识专家网友:往事埋风中
  • 2021-01-15 14:48
是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思。
str():将变量转化为字符串类型
a = 1
b = [1, 2, 3]
str_a = str(a)
print(a)
print(type(a))
str_b = str(b)
print(b)
print(type(b))
The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by
the interpreter (or will force a SyntaxError if there is not equivalent syntax). For objects which don't have a particular representation for human consumption, str() will
return the same value as repr(). Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings and。
全部回答
  • 1楼网友:人類模型
  • 2021-01-15 15:04
# str(): 将变量转化为字符串类型
a = 1
b = [1, 2, 3]
str_a = str(a)
print(a)
print(type(a))
str_b = str(b)
print(b)
print(type(b))
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息