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. Pycharm连接Mysql失败. [08001] Could not create connection to database server.

    使用Pycharm连接MySQL时遇到如下问题,错误代码[08001] 查了很多资料归纳一下可能是如下几个原因 0.mysql.server没开 找到对应系统下的mysql.server 启动/重启命 ...

  2. 二十一、JavaScript之访问对象属性

    一.代码如下 二.执行效果如下 <!DOCTYPE html> <html> <meta http-equiv="Content-Type" cont ...

  3. 七十五、SAP中数据库的使用SQL

    一.在SAP中可以使用两张数据库,一直是NativeSQL和OPEN SQL. Native SQL(本地SQL)特点: 1.每种关系型数据库都有其对应的  SQL,是数据库相关的. 2.不同的 SA ...

  4. C#不显示在任务栏

    在我用c#写一些小程序是总是希望,程序窗体不在任务栏上显示程序的窗体,c# Form提供了一个 属性值可以很好的解决这个问题 这个属性就是 ShowInTaskbar 在微软的官方声明格式为: pub ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-edit

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  6. .NET via C#笔记5——基元类型,引用类型和值类型

    5 基元类型,引用类型和值类型 5.3 值类型的装箱和拆箱 将值类型转化为引用类型需要进行装箱(boxing) 赋值,传参等操作,如果从值类型转为引用类型,都会进行装箱 装箱的代价比较大 申请一块堆内 ...

  7. Es知识整理

    一.Es是如何实现分布式的 1.Es本身基于lucene,高度支持分布式的核心思想就在于,在多个服务器上启动多个Es进程实例,组建了一套Es集群. 2.其次,因为shard分片的应用,非常灵活的支持数 ...

  8. POJ 1045:Bode Plot

    Bode Plot Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13392   Accepted: 8462 Descri ...

  9. android:padding和android:margin的区别 android:gravity和 android:layout_gravity 区别

    Android的Margin和Padding跟Html的是一样的.如下图所示:橙色边框(一个RelativeLayout或者LinearLayout)为例,最外层灰色为屏幕边框,黄色部分为Paddin ...

  10. Hive鲜为人知的宝石-Hooks

    本来想祝大家节日快乐,哎,无奈浪尖还在写文章.谴责一下,那些今天不学习的人.对于今天入星球的人,今天调低了一点价格.减少了20大洋.机不可失失不再来.点击阅读原文或者扫底部二维码. hive概述 Hi ...