yanzi-anqi

1.python3中标准数据类型
1)字符串;2)Number(数字);3)String(字符串);4)List(列表);5)Tuple(元组);6)Set(集合);7)Dictionary(字典)

2.元组表示:()
a = (1, 2) 或 a = 1, 2
print(type(a)) #得到tuple类型

# 元组只有1个元素的时候,一定要加上一个,
b = (1, )
print(type(b))

# 空元祖
e = ()
print(type(e))

# python中元组可以存储任何类型的数据
f = (1, 'ab', (1, 2), True)
print(type(f))

# 元组解包
(a, b) = ('yanzi', 'anqi')
print(a)    #得到a='yanzi'
print(b)    #得到b='anqi'

 # 元组取值,根据索引取值
name = ('yanzi', 'anqi', 'zy')
a = name[0]
b = name[1]
c = name[2]
print(c)

# 元组切片
print(name[1:3])    #得到('anqi', 'zy'),切片之后还是元组

#元组自带的函数,count统计次数,index统计索引    
print(name.count("yanzi"))
print(name.index("zy"))

分类:

技术点:

相关文章:

  • 2021-06-05
  • 2021-08-17
  • 2021-07-24
  • 2021-11-28
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-12-16
猜你喜欢
  • 2021-06-25
  • 2021-11-06
  • 2020-06-02
  • 2019-09-04
  • 2022-01-07
  • 2021-11-18
  • 2021-07-31
相关资源
相似解决方案