python之字符串

1、在python中字符串(str=’abc’)是无法改变的:

str='add'
str[1]='c'
*Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    str[1]='c'
TypeError: 'str' object does not support item assignment*

但是可以格式化字符串的方式来改变

str='it is a %s day'
str % 'sunny'->it is a sunny day

2、讲数字字符串‘4’变成可以参加数学运算的数字4:

int('4')

讲数字4变成字符串str(4)

你可能感兴趣的:(python)