Python学习笔记_基础篇(三)_数据类型之列表

一.基本数据类型
整数:int
字符串:str(注:\t等于一个tab键)
布尔值: bool
列表:list (元素的集合)
列表用[]
元祖:tuple
元祖用()
字典:dict
注:所有的数据类型都存在想对应的类列里

二.列表所有数据类型:

基本操作:

  • 索引
  • 切片
  • 追加
  • 删除
  • 长度
  • 切片
  • 循环
  • 包含

list

class list(object):"""list() -> new empty listlist(iterable) -> new list initialized from iterable's items"""def append(self, p_object): # real signature unknown; restored from __doc__""" L.append(object) -> None -- append object to end """(L.append(对象)- >——没有一个对象附加到结束)passdef clear(self): # real signature unknown; restored from __doc__""" L.clear() -> None -- remove all items from L """(L.clear()- >没有,把所有项目从L)passdef copy(self): # real signature unknown; restored from __doc__""" L.copy() -> list -- a shallow copy of L """(L.copy()- >列表- L的浅拷贝)return []def count(self, value): # real signature unknown; restored from __doc__""" L.count(value) -> integer -- return number of occurrences of value """(L.count(价值)- >整数,返回值的出现次数)return 0def extend(self, iterable): # real signature unknown; restored from __doc__""" L.extend(iterable) -> None -- extend list by appending elements from the iterable """(L.extend(iterable)- >没有——从iterable扩展列表通过添加元)passdef index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__"""L.index(value, [start, [stop]]) -> integer -- return first index of value.Raises ValueError if the value is not present.(l指数(价值,[开始,[不要]])- >整数,返回第一索引值。提出了ValueError如果不存在的价值。)"""return 0def insert(self, index, p_object): # real signature unknown; restored from __doc__""" L.insert(index, object) -- insert object before index """(l插入(指数(对象)——前插入对象索引)passdef pop(self, index=None): # real signature unknown; restored from __doc__"""L.pop([index]) -> item -- remove and return item at index (default last).Raises IndexError if list is empty or index is out of range.(L.pop((指数))- >项目——删除并返回项指数(默认)。提出了IndexError如果列表为空或索引的范围。)"""passdef remove(self, value): # real signature unknown; restored from __doc__"""L.remove(value) -> None -- remove first occurrence of value.Raises ValueError if the value is not present."""(L.remove(价值)- >没有,删除第一次出现的值。提出了ValueError如果不存在的价值。)passdef reverse(self): # real signature unknown; restored from __doc__""" L.reverse() -- reverse *IN PLACE* """passdef sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__""" L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """passdef __add__(self, *args, **kwargs): # real signature unknown""" Return self+value. """passdef __contains__(self, *args, **kwargs): # real signature unknown""" Return key in self. """passdef __delitem__(self, *args, **kwargs): # real signature unknown""" Delete self[key]. """passdef __eq__(self, *args, **kwargs): # real signature unknown""" Return self==value. """passdef __getattribute__(self, *args, **kwargs): # real signature unknown""" Return getattr(self, name). """passdef __getitem__(self, y): # real signature unknown; restored from __doc__""" x.__getitem__(y) <==> x[y] """passdef __ge__(self, *args, **kwargs): # real signature unknown""" Return self>=value. """passdef __gt__(self, *args, **kwargs): # real signature unknown""" Return self>value. """passdef __iadd__(self, *args, **kwargs): # real signature unknown""" Implement self+=value. """passdef __imul__(self, *args, **kwargs): # real signature unknown""" Implement self*=value. """passdef __init__(self, seq=()): # known special case of list.__init__"""list() -> new empty listlist(iterable) -> new list initialized from iterable's items# (copied from class doc)"""passdef __iter__(self, *args, **kwargs): # real signature unknown""" Implement iter(self). """passdef __len__(self, *args, **kwargs): # real signature unknown""" Return len(self). """passdef __le__(self, *args, **kwargs): # real signature unknown""" Return self<=value. """passdef __lt__(self, *args, **kwargs): # real signature unknown""" Return self<value. """passdef __mul__(self, *args, **kwargs): # real signature unknown""" Return self*value.n """pass@staticmethod # known case of __new__def __new__(*args, **kwargs): # real signature unknown""" Create and return a new object.  See help(type) for accurate signature. """passdef __ne__(self, *args, **kwargs): # real signature unknown""" Return self!=value. """passdef __repr__(self, *args, **kwargs): # real signature unknown""" Return repr(self). """passdef __reversed__(self): # real signature unknown; restored from __doc__""" L.__reversed__() -- return a reverse iterator over the list """passdef __rmul__(self, *args, **kwargs): # real signature unknown""" Return self*value. """passdef __setitem__(self, *args, **kwargs): # real signature unknown""" Set self[key] to value. """passdef __sizeof__(self): # real signature unknown; restored from __doc__""" L.__sizeof__() -- size of L in memory, in bytes """pass__hash__ = None

三.所有列表数据类型举例

#!/usr/bin/env python
# -*- coding:utf-8 -*-#append追加
name_list = ["zhangyanlin","suoning","nick"]
name_list.append('zhang')
print(name_list)#count制定字符出现几次
name_list = ["zhangyanlin","suoning","nick"]
name_list.append('zhang')
name_list.append('zhang')
name_list.append('zhang')
print(name_list.count('zhang'))#extend可扩展,批量往里加数据
name_list = ["zhangyanlin","suoning","nick"]
name = ["aylin","zhang","yan","lin"]
name_list.extend(name)
print(name_list)#index找到字符所在的位置
name_list = ["zhangyanlin","suoning","nick"]
print(name_list.index('nick'))#insert插入,往索引里面插入值
name_list = ["zhangyanlin","suoning","nick"]
name_list.insert(1,"zhang")
print(name_list)#pop在原列表中移除掉最后一个元素,并赋值给另一个变量
name_list = ["zhangyanlin","suoning","nick"]
name = name_list.pop()
print(name)#remove移除,只移除从左边找到的第一个
name_list = ["zhangyanlin","suoning","nick"]
name_list.remove('nick')
print(name_list)#reverse反转
name_list = ["zhangyanlin","suoning","nick"]
name_list.reverse()
print(name_list)#del删除其中元素,删除1到3之间的
name_list = ["zhangyanlin","suoning","nick"]
del name_list[1:3]
print(name_list)

四.索引

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[0])

五.切片

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[0:2])

六.总长度len

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[1:len(name_list)])

七.for循环

name_list = ["zhangyanlin","suoning""aylin""nick"]
for i in name_list:print(i)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/67442.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【量化课程】08_2.深度学习量化策略基础实战

文章目录 1. 深度学习简介2. 常用深度学习模型架构2.1 LSTM 介绍2.2 LSTM在股票预测中的应用 3. 模块分类3.1 卷积层3.2 池化层3.3 全连接层3.4 Dropout层 4. 深度学习模型构建5. 策略实现 1. 深度学习简介 深度学习是模拟人脑进行分析学习的神经网络。 2. 常用深度学习模型架…

Python语言入门简介

一、Python的历史 关键点: Python是一种用途广泛、解释性、面向对象的程序设计语言。 Python是新西兰的Guido van Rossum在1990 年创建的&#xff0c;它以英国流行喜剧“Monty Python的飞行马戏团”命名。van Rossum将Python开发作为一个嗜好&#xff0c;Python 因其简单、简洁…

flutter开发实战-实现左右来回移动的按钮引导动画效果

flutter开发实战-实现左右来回移动的按钮引导动画效果 最近开发过程中需要实现左右来回移动的按钮引导动画效果 一、动画 AnimationController用来控制一个或者多个动画的正向、反向、停止等相关动画操作。在默认情况下AnimationController是按照线性进行动画播放的。Animati…

VBA技术资料MF42:VBA_从Excel中上面的单元格复制公式

【分享成果&#xff0c;随喜正能量】唯有梦想才配让你不安&#xff0c;唯有行动才能解除你的不安.绳锯木断&#xff0c;水滴石穿。也许你现在做的事情很小&#xff0c;只要你能日积月累的坚持下去&#xff0c;才会发现意义非凡。所谓的成功&#xff0c;便是别人失败的时候你还在…

每天一道leetcode:剑指 Offer 13. 机器人的运动范围(中等广度优先遍历剪枝)

今日份题目&#xff1a; 地上有一个m行n列的方格&#xff0c;从坐标 [0,0] 到坐标 [m-1,n-1] 。一个机器人从坐标 [0, 0]的格子开始移动&#xff0c;它每次可以向左、右、上、下移动一格&#xff08;不能移动到方格外&#xff09;&#xff0c;也不能进入行坐标和列坐标的数位之…

ArcGIS入门操作手册

一.ArcGIS安装过程 参考本人博客&#xff1a;保姆级Arcgis安装图文安装教程_追忆苔上雪的博客-CSDN博客 二.ArcGIS植被指数计算 (1)使用工具&#xff1a;栅格计算器 打开软件&#xff0c;右侧搜索栅格计算器打开&#xff0c;要是搜索栏不小心叉掉找不到了&#xff0c;可以通…

从零开始 Spring Cloud 10:Elasticsearch

从零开始 Spring Cloud 10&#xff1a;Elasticsearch 图源&#xff1a;laiketui.com 基础 什么是 Elasticsearch Elasticsearch 是一个开源搜索引擎&#xff0c;可以用它实现从海量数据中对数据的高效查询。 关于 Elasticsearch 的历史渊源以及广泛用途&#xff0c;可以观看…

地理数据的双重呈现:GIS与数据可视化

前一篇文章带大家了解了GIS与三维GIS的关系&#xff0c;本文就GIS话题带大家一起探讨一下GIS和数据可视化之间的关系。 GIS&#xff08;地理信息系统&#xff09;和数据可视化在地理信息科学领域扮演着重要的角色&#xff0c;它们之间密切相关且相互增强。GIS是一种用于采集、…

Spark_Spark中 Stage, Job 划分依据 , Job, Stage, Task 高阶知识

上一篇文章中 &#xff1a; Spark_Spark 中 Stage, Job 划分依据 , Job, Stage, Task 基础知识_spark stage job_高达一号的博客-CSDN博客 主要解读了Stage, job, task 的划分标准&#xff0c;这篇文章将对这些信息进行进一步解读。 一. Job、Stage、Task的概念 在讲Spark的任…

【图像分类】理论篇 (4)图像增强opencv实现

随机旋转 随机旋转是一种图像增强技术&#xff0c;它通过将图像以随机角度进行旋转来增加数据的多样性&#xff0c;从而帮助改善模型的鲁棒性和泛化能力。这在训练深度学习模型时尤其有用&#xff0c;可以使模型更好地适应各种角度的输入。 原图像&#xff1a; 旋转后的图像&…

DevOps系列文章 之 Gitlab+Docker自动部署SpringBoot

1.环境要求 以下服务器的操作系统均为Centos7 服务器A&#xff1a;Gitlab服务器B&#xff1a;GitlabRunner、Docker、docker-compose、Java1.8、maven3.6.3、git ps&#xff1a;这里可以把服务器B的GitlabRunner、Java1.8、maven3.6.3、git单独提出来&#xff0c;独立部署&a…

数据结构:力扣OJ题(每日一练)

题一&#xff1a;有效的括号 给定一个只包括 (&#xff0c;)&#xff0c;{&#xff0c;}&#xff0c;[&#xff0c;] 的字符串 s &#xff0c;判断字符串是否有效。 有效字符串需满足&#xff1a; 左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。每个右括号…