3.9.1 - Lists in Python
来源:互联网 发布:网上开淘宝店流程 编辑:程序博客网 时间:2024/05/21 13:55
# Python List Examplesa = [] #Empty Listb = [0, 1, 2, 3, 4] #List with 5 itemsc = [3.14, "abc", [1, 2, 3, 4]] #List with a nested listd = list('Python') # List of iterable itemse = list(range(0, 10)) # List of integers from 0-9len(b)len(c[2])b + cc + bb * 43.14 in cb[2] = 9 # mutabletemp_string = "Python"temp_string[2] = "a" # error inmutablec[2][0]c[2][-1]b[1:]b[:2]b[1:3]
运行结果如下:
a = [] #Empty List
b = [0, 1, 2, 3, 4] #List with 5 items
c = [3.14, "abc", [1, 2, 3, 4]] #List with a nested list
d = list('Python') # List of iterable items
d
// Result: ['P', 'y', 't', 'h', 'o', 'n'] //
e = list(range(0, 10)) # List of integers from 0-9
e
// Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] //
len(b)
// Result: 5 //
len(c[2])
// Result: 4 //
b + c
// Result: [0, 1, 2, 3, 4, 3.14, 'abc', [1, 2, 3, 4]] //
c + b
// Result: [3.14, 'abc', [1, 2, 3, 4], 0, 1, 2, 3, 4] //
b * 4
// Result: [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4] //
3.14 in c
// Result: True //
b[2] = 9 # mutable
b
// Result: [0, 1, 9, 3, 4] //
c[2][0]
// Result: 1 //
c[2][-1]
// Result: 4 //
b[1:]
// Result: [1, 9, 3, 4] //
b[:2]
// Result: [0, 1] //
b[1:3]
// Result: [1, 9] //
- 3.9.1 - Lists in Python
- More on Lists in Python----深入Python列表
- Python -- Lists
- Python.Lists
- Using Lists as Stacks in Python----在Python中把链表当作堆栈使用
- Using Lists as Queues in Python----在Python中把链表当作队列使用
- Python中Lists浅析
- Python 列表(Lists)
- Python 列表(Lists)
- Python 列表(Lists)
- python 列表(Lists)
- Python HackerRank|Lists
- Variable argument lists in Cocoa
- An Introduction to Python Lists
- python学习笔记15--Lists
- Think Python: Chapter 10 Lists
- An Introduction to Python Lists
- Python中的Numbers,Strings,Lists
- uboot - 主Makefile分析【3】
- 3.7.7 - String Formatting
- 黑马程序员——Java基础——面向对象
- 3.8 - Using the Print Function
- Android-xml解析之PULL解析
- 3.9.1 - Lists in Python
- Struts2中Action的属性接收参数
- BytesWritable使用
- 学那么多东西有屁用,不如先建立自己的知识体系
- 3.9.2 - Lists - Adding and Removing Objects
- 3.9.3 - Sorting Lists
- 3.10 - Maya Commands: ls
- 3.11 - Dictionaries in Python
- 3.12 - Tuples in Python