吴裕雄--天生自然 PYTHON3开发学习:列表
list1 = ['Google', 'Runoob', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"];
list1 = ['Google', 'Runoob', 1997, 2000];
list2 = [1, 2, 3, 4, 5, 6, 7 ]; print ("list1[0]: ", list1[0])
print ("list2[1:5]: ", list2[1:5])
list = ['Google', 'Runoob', 1997, 2000]
print ("第三个元素为 : ", list[2])
list[2] = 2001
print ("更新后的第三个元素为 : ", list[2])
list = ['Google', 'Runoob', 1997, 2000]
print ("原始列表 : ", list)
del list[2]
print ("删除第三个元素 : ", list)
list1 = ['Google', 'Runoob', 'Taobao']
print (len(list1))
list2=list(range(5)) # 创建一个 0-4 的列表
print (len(list2))
list1, list2 = ['Google', 'Runoob', 'Taobao'], [456, 700, 200]
print ("list1 最大元素值 : ", max(list1))
print ("list2 最大元素值 : ", max(list2))
list1, list2 = ['Google', 'Runoob', 'Taobao'], [456, 700, 200]
print ("list1 最小元素值 : ", min(list1))
print ("list2 最小元素值 : ", min(list2))
aTuple = (123, 'Google', 'Runoob', 'Taobao')
list1 = list(aTuple)
print ("列表元素 : ", list1) str="Hello World"
list2=list(str)
print ("列表元素 : ", list2)
list1 = ['Google', 'Runoob', 'Taobao']
list1.append('Baidu')
print ("更新后的列表 : ", list1)
aList = [123, 'Google', 'Runoob', 'Taobao', 123];
print ("123 元素个数 : ", aList.count(123))
print ("Runoob 元素个数 : ", aList.count('Runoob'))
list1 = ['Google', 'Runoob', 'Taobao']
list2=list(range(5)) # 创建 0-4 的列表
list1.extend(list2) # 扩展列表
print ("扩展后的列表:", list1)
# 语言列表
language = ['French', 'English', 'German'] # 元组
language_tuple = ('Spanish', 'Portuguese') # 集合
language_set = {'Chinese', 'Japanese'} # 添加元组元素到列表末尾
language.extend(language_tuple) print('新列表: ', language) # 添加集合元素到列表末尾
language.extend(language_set) print('新列表: ', language)
list1 = ['Google', 'Runoob', 'Taobao']
print ('Runoob 索引值为', list1.index('Runoob'))
print ('Taobao 索引值为', list1.index('Taobao'))
list1 = ['Google', 'Runoob', 'Taobao']
list1.insert(1, 'Baidu')
print ('列表插入元素后为 : ', list1)
list1 = ['Google', 'Runoob', 'Taobao']
list1.pop()
print ("列表现在为 : ", list1)
list1.pop(1)
print ("列表现在为 : ", list1)
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']
list1.remove('Taobao')
print ("列表现在为 : ", list1)
list1.remove('Baidu')
print ("列表现在为 : ", list1)
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']
list1.reverse()
print ("列表反转后: ", list1)
aList = ['Google', 'Runoob', 'Taobao', 'Facebook'] aList.sort()
print ( "List : ", aList)
# 列表
vowels = ['e', 'a', 'u', 'o', 'i'] # 降序
vowels.sort(reverse=True) # 输出结果
print ( '降序输出:', vowels )
# 获取列表的第二个元素
def takeSecond(elem):
return elem[1] # 列表
random = [(2, 2), (3, 4), (4, 1), (1, 3)] # 指定第二个元素排序
random.sort(key=takeSecond) # 输出类别
print ('排序列表:', random)
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']
list1.clear()
print ("列表清空后 : ", list1)
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']
list2 = list1.copy()
print ("list2 列表: ", list2)
吴裕雄--天生自然 PYTHON3开发学习:列表的更多相关文章
- 吴裕雄--天生自然 PYTHON3开发学习:数字(Number)
print ("abs(-40) : ", abs(-40)) print ("abs(100.10) : ", abs(100.10)) #!/usr/bin ...
- 吴裕雄--天生自然 PYTHON3开发学习:运算符
#!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("1 - c 的值为:", c) c = a - b print ( ...
- 吴裕雄--天生自然 PYTHON3开发学习:基本数据类型
#!/usr/bin/python3 counter = 100 # 整型变量 miles = 1000.0 # 浮点型变量 name = "runoob" # 字符串 print ...
- 吴裕雄--天生自然 PYTHON3开发学习:函数
def 函数名(参数列表): 函数体 # 计算面积函数 def area(width, height): return width * height def print_welcome(name): ...
- 吴裕雄--天生自然 PYTHON3开发学习:MySQL - mysql-connector 驱动
import mysql.connector mydb = mysql.connector.connect( host="localhost", # 数据库主机地址 user=&q ...
- 吴裕雄--天生自然 PYTHON3开发学习:字符串
var1 = 'Hello World!' var2 = "Runoob" #!/usr/bin/python3 var1 = 'Hello World!' var2 = &quo ...
- 吴裕雄--天生自然 PYTHON3开发学习:基础语法
#!/usr/bin/python3 # 第一个注释 print ("Hello, Python!") # 第二个注释 #!/usr/bin/python3 # 第一个注释 # 第 ...
- 吴裕雄--天生自然 PYTHON3开发学习:多线程
import _thread import time # 为线程定义一个函数 def print_time( threadName, delay): count = 0 while count < ...
- 吴裕雄--天生自然 PYTHON3开发学习:数据库连接 - PyMySQL 驱动
import pymysql # 打开数据库连接 db = pymysql.connect("localhost","testuser","test1 ...
随机推荐
- 【SQL必知必会笔记(2)】检索数据、排序检索数据
上个笔记中介绍了一些关于数据库.SQL的基础知识,并且创建我们后续练习所需的数据库.表以及表之间的关系,从本文开始进入我们的正题:SQL语句的练习. 文章目录 1.检索数据(SELECT语句) 1.1 ...
- Lombok认知
Lombok的简介 Lombok是一款Java开发插件,公司项目到处使用,整体效果很棒,代码更干净.Java开发人员可以节省出重复构建,诸如hashCode和equals这样的方法以及各种业务对象模型 ...
- 控制台连接oracle11g报ORA-12560异常
oracle11g R2 64bit oracleClient 11.2 32bit PL/SQL Developer 11.0.2 32bit 今天发现了一个奇怪的现象,如图: 后来发现机器上既有s ...
- Essay引用如何最大限度的降低抄袭率
今天要说到让无数人恨得要死.为了降重改的哭天喊地的“Paraphrase”.毕竟引用不是打两个引号复制粘贴就能凑字数完事的,无论国内外,都有查重率这个大敌在等着你.想要引用别人的论点论据,就少不了需要 ...
- VM ESXi虚拟化使用学习笔记
由于疫情原因,没有条件介绍安装部分的内容,也没有安装部分内容的相关截图,所以安装部分可以选择网上资料.但是只要熟练安装CentOS系统的,基本安装ESXi一看就会,设置主机地址方面有一定图形化界面,比 ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 循环
有的时候,可能需要多次执行同一块代码.一般情况下,语句是顺序执行的:函数中的第一个语句先执行,接着是第二个语句,依此类推. 编程语言提供了允许更为复杂的执行路径的多种控制结构. 循环语句允许我们多次执 ...
- spring boot配置druid连接池连接mysql
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Spring 事件(1)- 内置事件
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- jQuery中:first,:first-child,first()的使用区别
ul li:first 先获取页面中所有li节点对象数组,然后返回数组中的第一个li节点对象 . :first-child 选择器选取属于其父元素的第一个子元素的所有元素. first() 返回被 ...
- sql server 日期时间数据类型
1.日期和时间数据类型 (1)在sqlserver 2008之前,SQL Server 支持datetime 和 smalldatetime 两种日期时间数据类型.这两种数据类型日期和时间是不可分割的 ...