103-字符串的定义和操作
Python中字符串的定义和操作
str1 = 'I am learning Python 101!'
print(str1)
# I am learning Python 101!
str2 = "Python is fun. Machine learning is fun too."
print(str2)
# Python is fun. Machine learning is fun too.
# 使用加号 + 将多个字符串连接起来
str4 = 'Hey, ' + 'James!'
print(str4)
# 'Hey, James!'
# 使用乘号*将一个字符串复制多次
str5 = 'Python is FUN! ' # 字符串最后有一个空格
str6 = str5 * 3
print(str6)
# 'Python is FUN! Python is FUN! Python is FUN!'
# 字符串中的数字仅仅是字符
str7 = '123'
str8 = str7 * 3
print(str8)
# 123123123
str9 = '456'
str10 = str9 + str7
print(str10)
print(type(str10))
# 456123
# <class 'str'>