python str函数怎么用
答案:3 悬赏:40 手机版
解决时间 2021-12-28 19:39
- 提问者网友:浮克旳回音
- 2021-12-27 23:09
python str函数怎么用
最佳答案
- 五星知识达人网友:像个废品
- 2021-12-27 23:22
是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思。
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。
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-12-28 01:27
# 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))
- 2楼网友:舊物识亽
- 2021-12-28 00:58
上面那个是做合并加法+时的转换,返回的数据如果是整数序列,序列的加法就成了新增整型,并引起错误。而需要的是字符串的合并。
下面由于print打印函数默认会对最终输入的对象进行repr()字符表示化处理,所以不需要再次转换字符串
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯