博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
3.9.1 - Lists in Python
阅读量:4040 次
发布时间:2019-05-24

本文共 1163 字,大约阅读时间需要 3 分钟。

# 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] //

转载地址:http://twxdi.baihongyu.com/

你可能感兴趣的文章
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>
移植QT
查看>>
如此调用
查看>>
计算机的发展史
查看>>
带WiringPi库的交叉编译如何处理一
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>
Spring事务的七种传播行为
查看>>
ES写入找不到主节点问题排查
查看>>
Java8 HashMap集合解析
查看>>
欢迎使用CSDN-markdown编辑器
查看>>
Android计算器实现源码分析
查看>>
Android系统构架
查看>>
Android 跨应用程序访问窗口知识点总结
查看>>