字符串类型(string)

字符串是以单引号'或双引号"括起来的任意文本

创建字符串:

st = 'Hello World!'

py = 'Hello Python'

对应操作:

# 1   * 重复输出字符串
print('hello'*2)
 
# 2 [] ,[:] 通过索引获取字符串中字符,这里和列表的切片操作是相同的,具体内容见列表
print('hello world'[2:])
 
# 3 in  成员运算符 - 如果字符串中包含给定的字符返回 True
print('el' in 'hello')
 
# 4 %   格式字符串
name = make
print('make is a good teacher')
print('%s is a good teacher'%name)
 
 
# 5 +   字符串拼接
a='123'
b='abc'
c='789'
d1=a+b+c
print(d1)
# +效率低,该用join
d2=''.join([a,b,c])
print(d2)
原文地址:https://www.cnblogs.com/ktv588/p/13468884.html