& python sequence listing type string & tuple

String

序列:序号 列
012345678
索引
序列类型,就是带有索引的数据类型:字符串/列表/元祖
name = 'wuhao dsb'
#       012345678
name3 = name[0]
name2 = name[6:]
# 字符串/列表/元组共有方法
# 长度
print('len(name):',len(name))
print('wo' in name)
print('w' not in name)
for i in name:
    print(i)

#

List

# 列表
# 中括号内用都好隔开多个元素
lt = ['nick','handsome','wuhao','beautiful',1,1,1,1]
print(lt)

s = set(lt)#  列表可以用集合去重
lt = list(s)
print(lt)

A list of built-in method

# 列表的内置方法
lt = ['nick','handsome','wuhao','beautiful',1,1,1,1]
lt.append('yongjiu guzhang')
print(lt)


print('*'*50)

del lt[0] # 按照索引删除
print(lt)

print('*'*50)
print(lt)
lt.pop(0)
print(lt)
print('*'*50)

lt2 = lt.copy()
print(lt2)
print('*'*50)

# 翻转
lt.reverse()
print(lt)
print('*'*50)

# 排序
lt3 = [1,3,2,100,4,5]
lt3.sort()
print(lt3)
print('*'*50)
# 清除
lt4=lt3.clear()
print(lt4)

Tuple

# 元组# # 元组就是把列表的中括号换成小括号,然后他没有内置方法
lt = [1,3,2,100,4,5]

# 只可取不可更改
tu  =  (1,3,2,100,4,5)
print(tu[0])

Author: bean paste pubescens
out at: https://www.cnblogs.com/chenziqing/
view other blog, please click: https://www.cnblogs.com/chenziqing/
solidarity with the blogger: If you think the article helpful , you can click on the bottom right corner of the article [recommended] it. Your encouragement is the greatest power bloggers!

Micro letter:

Guess you like

Origin www.cnblogs.com/chenziqing/p/11206988.html