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开发学习:列表的更多相关文章

  1. 吴裕雄--天生自然 PYTHON3开发学习:数字(Number)

    print ("abs(-40) : ", abs(-40)) print ("abs(100.10) : ", abs(100.10)) #!/usr/bin ...

  2. 吴裕雄--天生自然 PYTHON3开发学习:运算符

    #!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("1 - c 的值为:", c) c = a - b print ( ...

  3. 吴裕雄--天生自然 PYTHON3开发学习:基本数据类型

    #!/usr/bin/python3 counter = 100 # 整型变量 miles = 1000.0 # 浮点型变量 name = "runoob" # 字符串 print ...

  4. 吴裕雄--天生自然 PYTHON3开发学习:函数

    def 函数名(参数列表): 函数体 # 计算面积函数 def area(width, height): return width * height def print_welcome(name): ...

  5. 吴裕雄--天生自然 PYTHON3开发学习:MySQL - mysql-connector 驱动

    import mysql.connector mydb = mysql.connector.connect( host="localhost", # 数据库主机地址 user=&q ...

  6. 吴裕雄--天生自然 PYTHON3开发学习:字符串

    var1 = 'Hello World!' var2 = "Runoob" #!/usr/bin/python3 var1 = 'Hello World!' var2 = &quo ...

  7. 吴裕雄--天生自然 PYTHON3开发学习:基础语法

    #!/usr/bin/python3 # 第一个注释 print ("Hello, Python!") # 第二个注释 #!/usr/bin/python3 # 第一个注释 # 第 ...

  8. 吴裕雄--天生自然 PYTHON3开发学习:多线程

    import _thread import time # 为线程定义一个函数 def print_time( threadName, delay): count = 0 while count < ...

  9. 吴裕雄--天生自然 PYTHON3开发学习:数据库连接 - PyMySQL 驱动

    import pymysql # 打开数据库连接 db = pymysql.connect("localhost","testuser","test1 ...

随机推荐

  1. 九十六、SAP中ALV事件之九,显示功能按钮栏中显示ALV加强工具栏

    一.排查了很久,终于找到问题所在.把问题解决了,代码如下: 二.运行效果如下 三.试一试,标准功能都可以用 完美

  2. Essay写作如何提升自己的辩驳水平?

    辩证思维在英文写作上的表现方式有许多种,今天来讲讲Counterargument&Rebut,广泛用于英文写作和口语辩论.其作用就是通过辩驳和你论点相反的意见,来突出自己的论点更正确. 话说衡 ...

  3. 四、React创建组件、 JSX使用、绑定数据、引用图片方式、数组(列表)循环输出

    接:https://www.cnblogs.com/chenxi188/p/11702799.html 用上节建好的my-app项目: my-app/ README.md node_modules/ ...

  4. 逆向--C函数和汇编

    C函数和汇编 C代码 (编译工具gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609平台ubuntu i386 32位) int bar(int c ...

  5. linux常用命令-关机、重启

    常用命令-关机.重启 命令 含义 reboot 重新启动操作系 shutdown –r now 重新启动操作系统,shutdown会给别的用户提示 shutdown -h now 立刻关机,其中now ...

  6. 远程控制使用kill软件映射内网进行远程控制(9.28 第十四天)

    1.能ping通IP情况下远程控制 设置kill软件中的端口.密码.上线列表 2.在软件的Bin\Plugins目录下找到Consys21.dll复制到/phpstudy/www目录下留作生成软件 3 ...

  7. JS - 使 input 失去焦点

    $(document).ready(function(){ $("body").click(function(){ if(!event.srcElement.type) {     ...

  8. MVC学生管理系统-阶段IV(修改学生信息)

    项目源码 :https://download.csdn.net/download/weixin_44718300/11091042 前期准备,主体框架, 学生列表显示  请看阶段一文章 添加学生信息 ...

  9. 10 Json(unity3D)

    //写入json文档注意事项: 1.在Asset下要有一个StreamingAssets文件夹 2.在文件夹内,有一个已创建好的json空文档 3.引入命名空间 using Litjson; usin ...

  10. 吴裕雄--天生自然Django框架开发笔记:Django Admin 管理工具

    Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.可以在项目的 settings.py 中的 INSTALLED_APPS 看到它: ...