一.创建
s1 = 'lenovo'
s2 = "QF"
s3 = """hello lenovo"""
s4 = '''hello world'''
s5 = """hello
shark
"""
s6 = '''hello
world'''
二.简单使用
1. \转义符
testimony = ‘This shirt doesn’t fit me’
words = ‘hello \nshark’
print (words)
2.+拼接
> In [1]: file_name= "成功的21个信念"
>
> In [2]: suffix = '.txt'
>
> In [3]: file_name = file_name + suffix
>
> In [4]: file_name Out[4]: '成功的21个信念.txt'
拼接只能是 字符串和字符串进行操作,不可以用 字符串和 一个非字符串类型的对象相加
In [5]: '你好' + 1 ## 这会报错的 字符串不能和整形相加
3.*复制
In [6]: "-" * 10
Out[6]: '----------'
In [7]: print('*' * 10)
**********
三.取值和切片
1.字符串 是 Python 中的一个 序列类型 的数据结构
- 存放的数据,在其内是有序的。
s1 = “shark”
序列类型的特点
-
序列里的每个数据被称为序列的一个元素
-
元素在序列里都是有个自己的位置的,这个位置被称为索引或
者叫偏移量,也有叫下标的, 从
0
开始,从左到右依次递增 -
序列中的每一个元素可以通过这个元素的索引来