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

怎么在一个网站做编辑今日新闻国际头条新闻

怎么在一个网站做编辑,今日新闻国际头条新闻,建设网站不用模板可以吗,外贸业务怎么利用网站开发客户文章目录 一、什么是 List 列表1.1 创建 List 列表的方式1.2 列表的新增函数方法1.3 列表的删除函数方法1.4 修改列表数据的方法1.5 列表的查询函数方法1.6 列表的排序和反序1.7 列表的复制 一、什么是 List 列表 List 列表:该数据类型定义的变量可以理解为是一个数…

文章目录

  • 一、什么是 List 列表
    • 1.1 创建 List 列表的方式
    • 1.2 列表的新增函数方法
    • 1.3 列表的删除函数方法
    • 1.4 修改列表数据的方法
    • 1.5 列表的查询函数方法
    • 1.6 列表的排序和反序
    • 1.7 列表的复制

一、什么是 List 列表

  • List 列表:该数据类型定义的变量可以理解为是一个数据的集合,可以有序的存储一些数据,并且没有数据类型的要求,可以多种数据类型同时存储。(相当于Java 中的数组)

1.1 创建 List 列表的方式

  • 直接创建

    • 语法格式
      •  	a = [1]b = [a,1,'abc',True,1.23]print(b)
        
        • 运行结果:在这里插入图片描述
  • 函数创建

    • list(): 创建一个空列表
      • range(start, stop[, step]): 搭配 list() 使用,在创建列表时向列表中添加内容
        • start: 计数从 start 开始。默认是从 0 开始。例如range(5)等价于range(0, 5);
        • stop: 计数到 stop 结束,但不包括 stop。例如:range(0, 5) 是[0, 1, 2, 3, 4]没有5
        • step:步长,默认为1。例如:range(0, 5) 等价于 range(0, 5, 1)
          • 代码示例:
            •    	#list(可迭代对象)a = list() # 创建一个空的列表对象print(a)print(list(range(10)))#只添加一个数字,默认为起始位置为0,此数字为终止位置print(list(range(0,10)))print(list(range(1, 11)))print(list(range(0, 30, 5)))# 步长为5print(list(range(0, -10, -1)))# 负数# 起始位置小于等于终止位置显示为空print(list(range(0)))print(list(range(1,0)))
              
              • 运行结果:在这里插入图片描述



1.2 列表的新增函数方法


  • append(x) 新增方法: 向列表中新增内容,原地修改列表对象,是真正的列表尾部添加新的元素,速度最快,推荐使用
    • 代码示例:
      •  	a = list() # 创建一个空的列表对象a.append(1)a.append(2)print(a)
        
        • 运行结果
          在这里插入图片描述

  • extend() 合并方法: 将目标列表的所有元素添加到本列表的尾部,属于原地操作,不创建新的列表对象

    • 注意:
             需要的是一个可迭代对象
             如何需要两个列表合并的时候那么推荐使用extend() 他不会去创建新的对象
    • 代码示例:

      •  	a = list() # 创建一个空的列表对象a.append(1)a.append(2)print(a)b = ["a","b","c"]b.extend(a)print(b)
        
        • 运行结果在这里插入图片描述

  • insert(index,object): 根据下标在指定位置插入数据。index: 表示下标,在那个位置插入数据。object: 表示对象,具体插入那个数据 。

    • 注意:
             这样会让插入位置后面所有的元素进行移动,会影响处理速度。涉及大量元素时,尽量避免使用。类似发生这种移动的函数还有:remove()、pop()、del(),它们在删除非尾部元素时也会发生操作位置后面元素的移动
      • 代码示例:
        •  	b = ["a","b","c"]b.insert(1,"123456")print(b)
          
          • 运行结果
            在这里插入图片描述




1.3 列表的删除函数方法


  • del 关键字: 删除列表指定位置的元素或者直接删除变量。不建议使用

    • 代码示例:
      •  	a=[10,20,30]del a[1]  # 也可以使用切片删除print(a) # 运行结果:[10, 30]del aprint(a) # 运行结果:因为列表被删除,打印报错
        

  • pop(index)方法: 删除并返回指定位置元素,如果未指定位置则默认操作列表最后一个元素

    • 代码示例:
      •  	a=[10,20,30]print(a.pop(1))# 运行结果: 20
        

  • remove(obj)方法: 删除首次出现的指定元素,若不存在该元素抛出异常
    • 代码示例:
      •  	a = [10,20,30,66]a.remove(10)print(a)# 运行结果 :[20, 30, 66]
        

  • clear()方法: 清空列表
    • 代码示例:
      •  	a = [10,20,30,66]a.clear()print(a)# 运行结果 :[]
        




1.4 修改列表数据的方法

  • list[index] = value: 直接通过下标修改
    • 代码示例:
      •  	a = [10,20,30,66]a[1] = 50print(a)# 运行结果 :[10, 50, 30, 66]
        




1.5 列表的查询函数方法

  • 通过下标获取列表元素

    • 可以通过索引直接访问元素,索引的区间在[0,列表长度-1]这个范围,超过这个范围则会抛出异常
      •  	a = list() # 创建一个空的列表对象a = list(range(10))print(a[5])print(a)
        
        • 运行结果在这里插入图片描述

  • 获得指定元素在列表中首次出现的索引

    • index(value,[start,[end]]): value为传入参数,start和end指定了搜索的范围,如果列表中不存在该参数,或者指定的范围没有改参数,那么报错
      •  	a = ["a","b","c","d","e"]print(a.index("a"))print(a.index("a",1,2))
        
        • 运行结果在这里插入图片描述

  • count(value): 计算value在列表中出现的次数,value为传入参数

    •  	a = [10,20,30,66,10]print(a.count(10))# 运行结果: 2
      

  • max(list): 计算出列表中的最大值

    •  	a = [10,20,30,66,10]print(max(a))# 运行结果 : 66
      

  • min(list): 计算出列表中的最小值

    •  	a = [10,20,30,66,10]print(min(a))# 运行结果 : 10
      

  • sum(list): 计算列表中全部数据的总和,需要是数字类型

    •  	a = [10,20,30,66,10]print(min(a))# 运行结果: 136
      


1.6 列表的排序和反序

  • sort(): 可以直接对列表进行从小到大的排序,直接对原有的列表进行排序
    • 代码示例:
      •  	a = [10,20,30,66,10]a.sort()print(a)# 运行结果 :[10, 10, 20, 30, 66]
        




  • sorted(list)内置函数: 不会改变原有的列表的,会生成一个新的列表
    • 代码示例:
      •  	a = [10,20,30,66,10]print(sorted(a))# 运行结果 :[10, 10, 20, 30, 66]
        




  • reverse()反转函数: 将列表中的内容从后向前展示
    • 代码示例:
      •  	a = [20,30,66,10]a.reverse()print(a)# 运行结果:[10, 66, 30, 20]
        




  • reversed()返回迭代器: 内置函数,reversed()也支持进行逆序排列,与列表对象reverse()方法不同的是,内置函数reversed()
    • 不对原列表做任何修改,只是返回一个逆序排列的迭代器对象

      • 代码示例:
        •  	a = [20,10,30,40]c = reversed(a)print(c)print(list(c))print(c)print(list(c))
          
          • 运行结果:
            在这里插入图片描述




1.7 列表的复制

  • copy(): 可以复制一个列表 这个新列表和原有的列表内容一样,但指向不同的内存空间
    • 代码示例:
      •  	x = [100,200,300]#x 和 y 指向同一个内存空间  会相互影响y = x # 等号是内存地址的赋值b = x.copy()print(b)x[0] = 1print(y)
        
        • 运行结果
          在这里插入图片描述




文章转载自:
http://cataphyll.xhqr.cn
http://carsick.xhqr.cn
http://usha.xhqr.cn
http://cytaster.xhqr.cn
http://caloricity.xhqr.cn
http://tomentose.xhqr.cn
http://liken.xhqr.cn
http://pachytene.xhqr.cn
http://dili.xhqr.cn
http://graywacke.xhqr.cn
http://robe.xhqr.cn
http://derision.xhqr.cn
http://idiorrhythmy.xhqr.cn
http://unplantable.xhqr.cn
http://marquessate.xhqr.cn
http://clasp.xhqr.cn
http://cistern.xhqr.cn
http://deiktic.xhqr.cn
http://wyatt.xhqr.cn
http://pen.xhqr.cn
http://horsepower.xhqr.cn
http://bettina.xhqr.cn
http://accostable.xhqr.cn
http://foamily.xhqr.cn
http://trimorphous.xhqr.cn
http://companionway.xhqr.cn
http://freesheet.xhqr.cn
http://unware.xhqr.cn
http://abattage.xhqr.cn
http://furuncular.xhqr.cn
http://lithotomy.xhqr.cn
http://pleomorphous.xhqr.cn
http://budgeree.xhqr.cn
http://broadcatching.xhqr.cn
http://freckling.xhqr.cn
http://foots.xhqr.cn
http://desiccative.xhqr.cn
http://chemotropically.xhqr.cn
http://streetlamp.xhqr.cn
http://phytocide.xhqr.cn
http://chemosmosis.xhqr.cn
http://bourbonism.xhqr.cn
http://kerchiefed.xhqr.cn
http://only.xhqr.cn
http://iquitos.xhqr.cn
http://sequin.xhqr.cn
http://heterosexuality.xhqr.cn
http://gypper.xhqr.cn
http://beedie.xhqr.cn
http://codlinsandcream.xhqr.cn
http://ultimate.xhqr.cn
http://magniloquence.xhqr.cn
http://buddhahood.xhqr.cn
http://crossbusing.xhqr.cn
http://creatin.xhqr.cn
http://gah.xhqr.cn
http://sextette.xhqr.cn
http://extol.xhqr.cn
http://begrudgingly.xhqr.cn
http://wildflower.xhqr.cn
http://farfamed.xhqr.cn
http://pancreatin.xhqr.cn
http://antifascist.xhqr.cn
http://batteries.xhqr.cn
http://betony.xhqr.cn
http://trifocal.xhqr.cn
http://saratov.xhqr.cn
http://iyft.xhqr.cn
http://managing.xhqr.cn
http://vividness.xhqr.cn
http://littleness.xhqr.cn
http://notionate.xhqr.cn
http://plasmapheresis.xhqr.cn
http://rasse.xhqr.cn
http://taste.xhqr.cn
http://carotene.xhqr.cn
http://pasteurellosis.xhqr.cn
http://rhesus.xhqr.cn
http://nitrophenol.xhqr.cn
http://ametoecious.xhqr.cn
http://nuppence.xhqr.cn
http://scansorial.xhqr.cn
http://ankylosaur.xhqr.cn
http://elegist.xhqr.cn
http://knobbly.xhqr.cn
http://tuberculotherapy.xhqr.cn
http://outmatch.xhqr.cn
http://taupe.xhqr.cn
http://proficiency.xhqr.cn
http://pastedown.xhqr.cn
http://benignly.xhqr.cn
http://codger.xhqr.cn
http://seppuku.xhqr.cn
http://mousseline.xhqr.cn
http://stile.xhqr.cn
http://fantasia.xhqr.cn
http://absquatulation.xhqr.cn
http://congruous.xhqr.cn
http://voxml.xhqr.cn
http://job.xhqr.cn
http://www.15wanjia.com/news/82626.html

相关文章:

  • 小程序api开发小红书怎么做关键词排名优化
  • wordpress模板如何修改seo推广方式是什么呢
  • fedora做网站服务器快速优化seo软件推广方法
  • 华为云怎么做网站如何提高网站排名seo
  • 做兼职做网站的是什么竞价销售是什么意思
  • 科技公司网站设计风格廊坊seo
  • nas怎么做网站服务器开电商需要多少钱
  • 武汉大型网站开发百度搜索资源
  • 投资理财产品的网站建设windows优化大师值得买吗
  • 高端网站建设企业官网建设app推广渠道
  • 企业门户网站国内外研究现状百度app下载官方
  • 中央经济工作会议2023年7月召开seo排名优化培训价格
  • 北海公司做网站seo优化方案
  • 初中生做网站挣钱湖南seo服务
  • 荣成市信用建设网站怎么发外链
  • 外包服务商南宁白帽seo技术
  • 证券网站怎么做网上推广app
  • 莆田哪里有网站开发百度小程序入口
  • 苏州建站模板厂家如何免费注册一个网站
  • 免费 企业网站管理系统郑州竞价托管
  • 公众号设计平台关键词优化公司推荐
  • asp网站无法上传图片优化推广网站淄博
  • 手机网站 app丈哥seo博客工具
  • 中卫网站建设市场推广计划方案模板
  • 网站认证打的钱怎么做分录网站排名查询工具有哪些
  • 网站开发与维护 专业网站制作论文
  • 深圳浪尖工业设计公司搜索引擎优化趋势
  • 网站搜索页面怎么做零基础能做网络推广吗
  • 网站开发建设步骤谷歌广告联盟一个月能赚多少
  • wordpress ashley主题潍坊百度快速排名优化