Python中的字符串特性(索引、切片、重复、连接、成员操作符号)

1、索引

  s = 'hello'
  print(s[0])
  print(s[1])

在这里插入图片描述

2、切片

  print(s[:3])
  print(s[0:3])
  print(s[0:4:2])   #s[start:end:step] 从start开始,到end-1结束
  print(s[:])
  print(s[::-1])
  print(s[1:])
  print(s[:-1])
  print(s[-1])

在这里插入图片描述

3、重复

  print(s * 5)

在这里插入图片描述

4、连接

  print('hello' + 'world')

在这里插入图片描述

5、成员操作符

  print('h' in s)
  print('q' in s)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42566251/article/details/94032147