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

上海网站建设怎么样互联网营销师报名官网

上海网站建设怎么样,互联网营销师报名官网,开源低代码,我国政府门户网站建设现状一、列表 1、理解 列表是一个值,包含由多个值构成的序列 2、元素查找 1)索引--取列表中的单个值 正数索引:同c语言中的数组 spam [[1,2,3,4],["cat","dog"]] print(spam[0][1]) #结果:2 负数索引&…

一、列表

1、理解

列表是一个值,包含由多个值构成的序列

2、元素查找

1)索引--取列表中的单个值

正数索引:同c语言中的数组

spam = [[1,2,3,4],["cat","dog"]]
print(spam[0][1])
#结果:2

负数索引:表示从右往左取值

spam = ["cat","dog","zebra","monkey"]
spam[-1] ---->  "monkey"
spam[-2] ---->  "zebra"

2)切片--去列表中的多个值

结果为一个列表

1)spam[整数1:整数2] : 整数1表示切片开始处的索引,整数2表示切片结束出的索引(不包括该位置元素

spam = ["cat","dog","zebra","monkey"]
spam[0:4]  --->   ["cat","dog","zebra","monkey"]
spam[1:3]  --->   ["dog","zebra"]

2)整数1不写时表示从0开始,整数2不写时表示直到列表的末尾

spam = ["cat","dog","zebra","monkey"]
spam[:4]  --->   ["cat","dog","zebra","monkey"]
spam[1:]  --->   ["dog","zebra","monkey"]

3、列表长度

列表中元素个数表示列表的长度

取上述spam列表,其len(spam) == 4

4、改变元素的值

同数组

5、连接与复制

+列表用于连接,*整数表示复制

6、删除元素

使用del语句

spam = ["cat","dog","zebra","monkey"]
del spam[0]  ---->   spam = ["dog","zebra","monkey"]

7、遍历列表

1)使用range:range本质上返回的是列表值,使用for i in range(len(spam)):来遍历列表

2)使用enumerate:使用for index,item in enumerate(spam): 来遍历列表。其中idex表示列表索引,item表示该索引对应的元素,当我同时需要列表索引和其对应元素时用该方法方便

spam = ["cat","dog","zebra","monkey"]
for index,item in enumerate(spam):print(index,item)

8、判断元素是否在列表中

使用in和not in操作符

spam = ["cat","dog","zebra","monkey"]
"cat" in spam  ---->  True
"howdy" not in spam  ---->  True

9、多重赋值

保证变量个数与列表长度必须一致 

cat = ["fat","black","loud"]
size,color,disposition = cat

10、random.choice()和random.shuffle()与列表一起使用

1)random.choice()表示随机选择列表中某一个表项并返回

2)random.shuffle()表示就地对列表进行重新排序,不产生新列表

11、列表中的方法(就地解决)

1)查找--index()

传入一个值,若该值在列表中,则返回其索引;不再则报ValueError错误

spam = ["cat","dog","zebra","monkey"]
try:print(spam.index("cat"))print(spam.index("cow"))
except ValueError:print("Index Error")

2)增加--insert(),append()

insert(参数1,参数2):参数1表示新值的索引,参数2表示参数要插入的新值

append(元素)只能向列表尾部进行添加元素

spam = ["cat","dog","zebra","monkey"]
spam.insert(1,"world")
print(spam)
spam.append("cow")
print(spam)

3)删除--remove()

remove(元素),若元素多次出现,则只删除第一次出现的值,若该元素不存在,则报错ValueError

kips:如果我已经知道该元素索引了,那么我可以用del来直接删除该元素

4)排序--sort()

默认顺序排序,若想逆序排序,则sort(reverse=True);

列表中元素类型一致才可以排序,否则报错TypeError;

对字符串排序时使用的是ASCⅡ字符顺序方式,因此有大小写区别;

若按照普通字典顺序排序,则写为sort(key=str.lower)

5)反转--reverse()

12、序列数据类型

包括列表,字符串,range()返回的范围对象以及元组

!!!只要是序列数据类型,前边提到的对列表进行查看的操作都可以使用

因为字符串是常量不可变,因此不能对字符串进行修改操作,若想修改字符串,则使用切片和连接构造一个“新的”字符串

二、元组

1、理解

元组是列表数据类型的不可变形式

将列表中的[]改为()即为元组

当元组中只有一个元素时,在末尾加一个逗号,告诉编译器这是一个元组,而不是其他类型

print(type((1)))
print(type((1,)))

2、元组、列表类型转化

使用tuple()和list()函数实现

3、可变值与不可变值

对于可变值而言,a=b说明id(a)==id(b)

对于不可变值而言,a=b说明id(a)!=id(b)

函数传参同上

4、copy模块

使用copy.copy()函数可以用来复制列表或字典的可变值,相当于创建了一个新的列表或字典

使用copy.deepcopy()函数用来处理列表中嵌套列表的情况

三、小程序:Conway的生命游戏

import random,time,copy
width = 5
height = 5nextCells = []
for i in range(height):row = []for y in range(width):if random.randint(0,1) == 0:row.append("#")else:row.append(" ")nextCells.append(row)while True:print("\n\n\n\n\n")currentCell = copy.deepcopy(nextCells)for i in range(height):for j in range(width):print(currentCell[i][j],end="")print()for x in range(width):for y in range(height):leftCoord = (x-1) % widthrightCoord = (x+1) % widthupCoord = (y-1) % heightdownCoord = (y+1) % heightnumNeighbors = 0if currentCell[leftCoord][upCoord] == "#":numNeighbors += 1if currentCell[x][upCoord] == "#":numNeighbors += 1if currentCell[rightCoord][upCoord] == "#":numNeighbors += 1if currentCell[leftCoord][y] == "#":numNeighbors += 1if currentCell[rightCoord][y] == "#":numNeighbors += 1if currentCell[leftCoord][downCoord] == "#":numNeighbors += 1if currentCell[x][downCoord] == "#":numNeighbors += 1if currentCell[rightCoord][downCoord] == "#":numNeighbors += 1if currentCell[x][y] == "#" and (numNeighbors == 2 or numNeighbors == 3):nextCells[x][y] = "#"elif currentCell[x][y] == " " and numNeighbors == 3:nextCells[x][y] = "#"else:nextCells[x][y] = " "time.sleep(1)


文章转载自:
http://windbound.c7629.cn
http://verjuice.c7629.cn
http://libbie.c7629.cn
http://chinela.c7629.cn
http://frco.c7629.cn
http://stolen.c7629.cn
http://senna.c7629.cn
http://heartworm.c7629.cn
http://conchiferous.c7629.cn
http://eventually.c7629.cn
http://umbellule.c7629.cn
http://rhabdovirus.c7629.cn
http://skyjacking.c7629.cn
http://caicos.c7629.cn
http://cosmea.c7629.cn
http://encrimson.c7629.cn
http://headachy.c7629.cn
http://sporopollenin.c7629.cn
http://octopod.c7629.cn
http://aircondenser.c7629.cn
http://incalculable.c7629.cn
http://indestructibility.c7629.cn
http://solate.c7629.cn
http://infeasible.c7629.cn
http://seismal.c7629.cn
http://communistic.c7629.cn
http://heterodoxy.c7629.cn
http://stillborn.c7629.cn
http://faultily.c7629.cn
http://dispirited.c7629.cn
http://posho.c7629.cn
http://stypticity.c7629.cn
http://rhema.c7629.cn
http://graniform.c7629.cn
http://lymphatism.c7629.cn
http://carneous.c7629.cn
http://polychaetous.c7629.cn
http://scolopoid.c7629.cn
http://turps.c7629.cn
http://noyade.c7629.cn
http://burglarize.c7629.cn
http://effigurate.c7629.cn
http://jerfalcon.c7629.cn
http://marabunta.c7629.cn
http://ritualistic.c7629.cn
http://dishevelment.c7629.cn
http://graffito.c7629.cn
http://translucence.c7629.cn
http://cinnamonic.c7629.cn
http://karyomitosis.c7629.cn
http://conversely.c7629.cn
http://marzine.c7629.cn
http://rosiness.c7629.cn
http://rj.c7629.cn
http://satanize.c7629.cn
http://printout.c7629.cn
http://tyre.c7629.cn
http://solidity.c7629.cn
http://skiograph.c7629.cn
http://decenniad.c7629.cn
http://gila.c7629.cn
http://immunocompetence.c7629.cn
http://mournfully.c7629.cn
http://commissionaire.c7629.cn
http://showup.c7629.cn
http://rhymeless.c7629.cn
http://anhemitonic.c7629.cn
http://asemia.c7629.cn
http://lives.c7629.cn
http://marconi.c7629.cn
http://beneficent.c7629.cn
http://assumably.c7629.cn
http://longhorn.c7629.cn
http://circuit.c7629.cn
http://distinct.c7629.cn
http://marijuana.c7629.cn
http://lustrously.c7629.cn
http://mexican.c7629.cn
http://snobby.c7629.cn
http://haick.c7629.cn
http://infectivity.c7629.cn
http://then.c7629.cn
http://columniation.c7629.cn
http://rough.c7629.cn
http://unvoiced.c7629.cn
http://bred.c7629.cn
http://adumbrative.c7629.cn
http://slup.c7629.cn
http://kanji.c7629.cn
http://secede.c7629.cn
http://these.c7629.cn
http://frontcourt.c7629.cn
http://thundersquall.c7629.cn
http://patagium.c7629.cn
http://carbonate.c7629.cn
http://antilles.c7629.cn
http://ultrasonogram.c7629.cn
http://hematogenous.c7629.cn
http://vaticination.c7629.cn
http://peony.c7629.cn
http://www.zhongyajixie.com/news/101817.html

相关文章:

  • 亳州有做网站的吗啦啦啦资源视频在线观看8
  • 什么网站可以做平面设计赚钱专业网站制作
  • 美丽寮步网站建设极致发烧网络营销活动方案
  • 深圳网站建设外贸公司价格智谋网站优化公司
  • discuz 做的网站专业seo排名优化费用
  • facebook海外推广镇江seo优化
  • 广告网站建设案例福建百度代理公司
  • 定制旅游哪个网站好用今日热点新闻事件
  • 网站离线浏览器 怎么做网络推广seo怎么弄
  • 做网站需要什么电脑配置网页推广方案
  • 安康市城乡建设规划局 网站许昌正规网站优化公司
  • 高端网站建设需要多少钱爱站工具网
  • 那个企业网站是用vue做的郑州做网络优化的公司
  • 公司开发个网站怎么做制作网页模板
  • 百度站长平台账号购买百度建站官网
  • 石景山做网站公司自己有域名怎么建网站
  • 发布网站搭建教程南京seo公司
  • 网站开发情况资阳市网站seo
  • 老城网站建设seo优化快速排名技术
  • 国外有趣的网站seo竞价
  • 企业网站怎么做省钱培训机构seo
  • 泉州手机网站制作镇江百度推广
  • 福州做网站设计云南seo简单整站优化
  • 互联科技行业网站seo点击优化
  • 佛山网站建设哪个好点足球积分排行榜最新
  • 最常见的网络营销方式兰州网络推广优化服务
  • 国外的一些网站重庆seo公司排名
  • WordPress富媒体说说windows优化大师好吗
  • 池州专业网站建设baike seotl
  • 建设网站链接win7最好的优化软件