不同点
###1、符号格式
区别 | 符号 | 实例 |
---|---|---|
字符串 | 单引号,双引号,三单引号,三双引号 | >>> area = ‘Gongshu’ >>> history = “5000” >>> school = “”“浙大,城院,树大”"" >>> river = ‘’‘陈家河,运河,西湖’’’ |
列表 | [] | li = [] li = [1, 2, 3, ‘abcd’, ‘city’, ‘collage’, [“I”, ‘love’, ‘you’]] |
元组 | () | tp =() tp = (1,) tp = (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘a’, ‘b’, ‘c’, (‘d’, ‘e’, ‘f’)) |
2、增删改查
(1)字符串
类别 | 函数 | 意思 | 实例 |
---|---|---|---|
增 | join() | 将指定字符插入到元素中间 | list = [“I”, “Love”, “Python”] print(’ '.join(list)) I Love Python |
删 | sr.strip() sr.lstrip() sr.rstrip() |
移除字符串头尾指定的字符 移除字符串左边指定的字符 移除字符串右边指定的字符 |
sr = “####Life is short,you need python.####“ print(sr.strip(”#”)) print(sr.lstrip("#")) print(sr.rstrip("#")) Life is short,you need python. Life is short,you need python.#### ####Life is short,you need python. |
改 | sr.lower() sr.upper() sr.swapcase() sr.title() sr.capitalize() |
转小写 转大写 大小写互换 转为标题的形式 首字母大写 |
sr = "Life is short,you need python." print(sr.lower()) print(sr.upper()) print(sr.swapcase()) print(sr.title()) print(sr.capitalize()) life is short,you need python. LIFE IS SHORT,YOU NEED PYTHON. lIFE IS SHORT,YOU NEED PYTHON. Life Is Short,You Need Python. Life is short,you need python. |
sr.center()< |