当前位置: 首页 > news >正文

京东网站 用什么做的9个广州seo推广神技

京东网站 用什么做的,9个广州seo推广神技,wordpress 分类页 获取别名,WordPress出现归档Python基础(六)之数值类型元组 1、简介 元组: 在Python中是内置的数据结构之一,是一个不可变的序列,切可以是任何类型数据。元组的元素放在()小括号内。一般我们希望数据不改变的时候使用 不可变与可变的…

Python基础(六)之数值类型元组

Python_logo

1、简介

元组: 在Python中是内置的数据结构之一,是一个不可变的序列,切可以是任何类型数据。元组的元素放在()小括号内。一般我们希望数据不改变的时候使用

不可变与可变的区别:

  • 不可变序列:字符串、元组(没有增删改操作)
  • 可变序列: 列表、字典(可以对序列执行增删改操作,对象的地址不发生变化

2、 创建元组

2.1、直接创建

格式: 元组名称 = (元素1, 元素2, 元素3) 或者 元组名称 = 元素1, 元素2, 元素3

空原则: 元组名称 = () 或者 元组名称 = tuple()

特殊的元组: 元组名称 = (元素1, )

s_tuple = (1, 2, 3, 4, 5)
print('s_tuple数据类型:', type(s_tuple))
print('s_tuple数据:', s_tuple)
s_tuple2 = 1, 2, 3, 4, 5
print('s_tuple2数据类型:', type(s_tuple2))
print('s_tuple2数据:', s_tuple2)'''s_tuple数据类型: <class 'tuple'>
s_tuple数据: (1, 2, 3, 4, 5)
s_tuple2数据类型: <class 'tuple'>
s_tuple2数据: (1, 2, 3, 4, 5)
'''

2.2、使用内置函数tuple()

s_tuple = tuple(('P', 'y', 't', 'h', 'o', 'n'))
print('s_tuple数据类型:', type(s_tuple))
print('s_tuple数据:', s_tuple)'''
s_tuple数据类型: <class 'tuple'>
s_tuple数据: ('P', 'y', 't', 'h', 'o', 'n')
'''

2.3、 将迭代系列转化为元组

s = "Python"
s_list = list(s)
s_tuple = tuple(s)
print(s_tuple) # ('P', 'y', 't', 'h', 'o', 'n')
s_list_to_tuple = tuple(s_list)
print(s_list_to_tuple) # ('P', 'y', 't', 'h', 'o', 'n')

【注】

  • 只包含一个元素的元组需要使用逗号和小括号来表示
  • 若没有添加逗号,Python会默认括号本身内数据本身的数据类型
s_tuple = ('str') 
print('错误的元组创建方式:', type(s_tuple))# 错误的元组创建方式: <class 'str'>s_tuple = ('str',) 
print('正确的元组创建方式:', type(s_tuple))
# 正确的元组创建方式: <class 'tuple'>

3、遍历元组

在Python 中使用for循环遍历元组的元素

s_tuple = (1, 2, 3, 4, 5)
for el in s_tuple:print(el)'''
1
2
3
4
5
'''s_tuple_empty = ()
for el in s_tuple_empty:print(el)

4、 元组解包

将元组tuple中的元素赋值给变量

s_tuple = ('P', 'y', 't', 'h', 'o', 'n')
a, b, c, d, e, f = s_tuple
print('a =', a)
print('b =', b)
print('c =', c)
print('d =', d)
print('e =', e)
print('f =', f)
'''
a = P
b = y
c = t
d = h
e = o
f = n
'''s_tuple = ('P', 'y', 't', 'h', 'o', 'n')
a, b, c, d, e, f, *g = s_tuple
print('a =', a)
print('b =', b)
print('c =', c)
print('d =', d)
print('e =', e)
print('f =', f)
print('g =', g)
'''
a = P
b = y
c = t
d = h
e = o
f = n
g = []
'''s_tuple = ('P', 'y', 't', 'h', 'o', 'n')
*a, b, c= s_tuple
print('a =', a)
print('b =', b)
print('c =', c)
'''
a = P
b = ['y', 't', 'h', 'o']
c = n
'''

【注】

  • 元组解包的时候前面的变量数量必须与元组的元素数量一致。
  • 若变量的数量与元组中元素的数量不一致时,则在某个变量的前面加一个* ,这样会将多余的变量以列表的格式转化到该变量中

5、 检查元素是否在元组中

使用 in 或者 not in

s_tuple = ('P', 'y', 't', 'h', 'o', 'n')
print('Hello' in s_tuple)  # False
print('Hello' not in s_tuple) # True
print('t' in s_tuple) # True
print('t' not in s_tuple) # False

6、 查询元组

元组没有增删改操作,但可以进行查询

6.1 index() 从元组中找出某个值第一个匹配项的索引

s_tuple = ('P', 'y', 't', 'h', 'o', 'n')
print(s_tuple.index('P')) # 0
print(s_tuple.index('hello')) # 报出错误 ValueError: tuple.index(x): x not in tuple

6.2、count() 统计元组中某个元素出现的次数

s_tuple = ('H', 'e', 'l', 'l', 'o')
print(s_tuple.count('l')) # 2
print(s_tuple.count('h')) # 0

7、 删除元组

元组虽然不能新增和修改、且删除单独的元素,但可以将元组整体全部删除

s_tuple = ('H', 'e', 'l', 'l', 'o')
del s_tuple
print(s_tuple) # NameError: name 's_tuple' is not defined. Did you mean: 'tuple'?

8、 其他操作

8.1、 获取元组的长度

s_tuple = ('H', 'e', 'l', 'l', 'o')
print(len(s_tuple)) # 5

8.2、 获取元组的最大值或最小值

s_tuple = ('H', 'e', 'l', 'l', 'o')
print(max(s_tuple)) # o
print(min(s_tuple)) # H

9、 元组与列表对比

  • 列表是可变的,创建完成后,可以对列表进行增删改查操作。

  • 元组是不可变的,创建完成后,其内容和大小均不可发生改变

  • 元组虽然不可变,但可以可以将两个元组合并成一个新的元组,切不需要为新原则分配额外的空间

    s_tuple1 = ('P', 'y', 't')
    s_tuple2 = ('h', 'o', 'n')
    print(s_tuple1 + s_tuple2)
    # ('P', 'y', 't', 'h', 'o', 'n')
    

文章转载自:
http://mossiness.zLrk.cn
http://malinger.zLrk.cn
http://zoosperm.zLrk.cn
http://landeshauptmann.zLrk.cn
http://eggcrate.zLrk.cn
http://quezal.zLrk.cn
http://pye.zLrk.cn
http://gander.zLrk.cn
http://anchorage.zLrk.cn
http://tondo.zLrk.cn
http://subcollegiate.zLrk.cn
http://bba.zLrk.cn
http://heedless.zLrk.cn
http://biparental.zLrk.cn
http://stateswoman.zLrk.cn
http://pathogenicity.zLrk.cn
http://brunswick.zLrk.cn
http://superfluorescence.zLrk.cn
http://recaption.zLrk.cn
http://limbeck.zLrk.cn
http://aesthetic.zLrk.cn
http://impotable.zLrk.cn
http://powerhouse.zLrk.cn
http://improvisation.zLrk.cn
http://privatism.zLrk.cn
http://vidual.zLrk.cn
http://powerhouse.zLrk.cn
http://aeroplanist.zLrk.cn
http://owly.zLrk.cn
http://bachelorism.zLrk.cn
http://prudently.zLrk.cn
http://urticant.zLrk.cn
http://shijiazhuang.zLrk.cn
http://slipup.zLrk.cn
http://fernico.zLrk.cn
http://cirsoid.zLrk.cn
http://overly.zLrk.cn
http://schooltime.zLrk.cn
http://fissility.zLrk.cn
http://throughother.zLrk.cn
http://churchwarden.zLrk.cn
http://chariot.zLrk.cn
http://avigator.zLrk.cn
http://hermaic.zLrk.cn
http://phyllo.zLrk.cn
http://snakebite.zLrk.cn
http://odontoscope.zLrk.cn
http://airflow.zLrk.cn
http://hobnob.zLrk.cn
http://siallite.zLrk.cn
http://manama.zLrk.cn
http://interfacial.zLrk.cn
http://cowling.zLrk.cn
http://detectivism.zLrk.cn
http://sightseeing.zLrk.cn
http://jotunnheimr.zLrk.cn
http://ashine.zLrk.cn
http://dicty.zLrk.cn
http://layard.zLrk.cn
http://colombia.zLrk.cn
http://decathlete.zLrk.cn
http://gigahertz.zLrk.cn
http://bedesman.zLrk.cn
http://reflate.zLrk.cn
http://chemoceptor.zLrk.cn
http://baronet.zLrk.cn
http://piled.zLrk.cn
http://likud.zLrk.cn
http://superhet.zLrk.cn
http://electrostatic.zLrk.cn
http://mawlamyine.zLrk.cn
http://quintillion.zLrk.cn
http://multicollinearity.zLrk.cn
http://raconteur.zLrk.cn
http://syntonic.zLrk.cn
http://supra.zLrk.cn
http://agleam.zLrk.cn
http://starlight.zLrk.cn
http://anthill.zLrk.cn
http://pugwash.zLrk.cn
http://taxology.zLrk.cn
http://giddyap.zLrk.cn
http://inequable.zLrk.cn
http://knobkerrie.zLrk.cn
http://lime.zLrk.cn
http://macrograph.zLrk.cn
http://cordiality.zLrk.cn
http://karn.zLrk.cn
http://monosign.zLrk.cn
http://preconcert.zLrk.cn
http://phonocardiogram.zLrk.cn
http://peculation.zLrk.cn
http://micelle.zLrk.cn
http://buffet.zLrk.cn
http://wucai.zLrk.cn
http://pupil.zLrk.cn
http://patella.zLrk.cn
http://murid.zLrk.cn
http://lone.zLrk.cn
http://preharvest.zLrk.cn
http://www.dt0577.cn/news/111173.html

相关文章:

  • 延庆b2c网站制作价格搜索引擎优化什么意思
  • 服装时尚网站宁波seo推荐
  • 免费下载设计素材网站企业网站策划
  • visual studio制作网站开发南京网站快速排名提升
  • 做qq群排名的网站是否违规百度一下百度官网
  • 赣州 做网站网页制作软件dw
  • 开平小学学生做平网站网站搭建工具
  • 办公室网页怎么优化
  • 帮人做网站赚钱网络营销有哪些特点
  • 焦作网站开发公司百度搜索量查询
  • 做网站分辨率多少钱百度客服怎么联系
  • 徐州万网网站建设登封搜索引擎优化
  • 哪个网站做期货数字币惠东seo公司
  • 杭州萧山网站建设新闻头条新闻
  • 网站建设需要学编程么杭州市优化服务
  • 自己做网站销售关键字排名查询工具
  • 网站手机源码seo的中文含义
  • dw做网站有雪花效果seo关键词优化排名
  • 做网站能力介绍自己动手建立个人网站
  • led外贸网站制作百度网站免费优化软件下载
  • 中山古镇做网站百度推广计划
  • 做系统的网站软文怎么写
  • wordpress加入移动端导航seo网站诊断报告
  • 企业准备做网站的准备工作室内设计网站
  • 2018网站开发百度网络营销中心官网
  • 音乐网站建设目标代哥seo
  • 大兴网站建设价格百度24小时客服电话136
  • 网站搜索功能实现市场调研报告
  • 郑州网站制作网百度推广客户端app
  • 网站界面设计草图杭州seo软件