Python中字符串的创建方法有以下几种:
str1 = 'Hello World'
str2 = "Python is awesome"
str3 = '''This is a
multi-line string'''
str4 = 'I\'m a programmer'
str5 = "He said, \"Hello World\""
str6 = r'C:\Users\Username\Desktop'
name = 'Alice'
age = 25
str7 = 'My name is {} and I am {} years old'.format(name, age)
str8 = 'Hello' + ' ' + 'World'
str9 = 'Python' * 3
需要注意的是,字符串是不可变的,即不能对字符串进行修改,但可以通过创建新的字符串来实现对字符串的修改。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python处理字符串的方法有哪些