老师好,字符串运算里面你只说到+和*,那 - 和 / 呢?是否没有?
来源:3-12 字符串运算 一

刺童邪
2018-07-16
写回答
1回答
-
水管工不打领带
2018-07-16
这种问题可以自己动手尝试,我在尝试后发现确实是不能应用于字符串的。报错如下:
>>> "hello world"-"hello"
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
"hello world"-"hello"
TypeError: unsupported operand type(s) for -: 'str' and 'str'
>>> "hello world"/"h"
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
"hello world"/"h"
TypeError: unsupported operand type(s) for /: 'str' and 'str'分别都报TypeError错误:操作符不支持以下类型:'str' 和 'str'
00
相似问题