0
点赞
收藏
分享

微信扫一扫

29 - python字符串的基本操作


# 通过索引获取字符串中的某个字符
s1 = 'hello world'
print(s1[0])
print(s1[-1])

h
d

# 分片
print(s1[6:11])
print(s1[:6])
print(s1[::2])
print(s1[::-1])

world
hello
hlowrd
dlrow olleh

# 乘法
print(s1 * 2)

hello worldhello world

print('b' in s1)
print('b' not in s1)

False
True

print(len(s1))
print(min(s1))
print(max(s1))

11

w

a = [1, 2, 3, 6, 7]
print(2 in a)
print(2 not in a)

True
False

print(max(a))
print(min(a))

7
1

print(2 * a)

[1, 2, 3, 6, 7, 1, 2, 3, 6, 7]

a[0] = 20
# s1[0] = 'a'

​​30 - 字符串的format方法​​


举报

相关推荐

0 条评论