part 1 string
1.访问字符串中的字符 左闭右开
点击查看代码
string = "abc" string[-2,-1] = 'n'
3.字符串连接用 \(\mathtt{'+'}\) 就不会有空格出现
4.字符串比较是按位比较 \(\texttt{ASCLL码}\)
5.字符串输出既可使用 \(\texttt{format}\) 也可以使用 \(\texttt{%s}\) 方法两者均可方便的输出多个变量
点击查看代码
法1:
age=4
print("He has a dog {} and it's age is {} years".format(dog,age))
法2:
lang="Programming language"
print("%s is a %s"%(var,lang))