- 字符串相加&相乘。
words1 = 'word' + 'word'
print(words1)
words2 = 'word' * 3
print(words2)
#结果为:
wordword
wordwordword
- 字符串的切片。
name = 'My name is Leo'
print(name[0]) # 'M'
print(name[-2]) # 'e'
print(name[2: 4]) # ' n'
print(name[1:]) # 'y name is Leo'
print(name[:3]) # My
# 冒号两边分别代表从哪里开始和哪里结束.
# name[2:4]表示从索引2至索引4之间的字符,包含索引为2的
# 字符不包含索引为4的字符;