[python3 - Basic] List
Posted break大蜗牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[python3 - Basic] List相关的知识,希望对你有一定的参考价值。
Attribute
1. len()
list = [1,2,3]
length = len(list)
Condition
1. 如果元素存在list中
list = [‘a‘, ‘b‘, ‘c‘] str = ‘a‘ if str in list:
print("This string is in the list.")
2. 如果list不为空
list = [] if not list: print ("List is empty.")
Add
1. append() - 在尾部加element
list = [1,2,3] list.append(4) # list=[1,2,3,4]
2. extend([]) - 在list后面,添加多个element
list1 = [‘a‘,‘b‘,‘c‘]
list2 = list1.extend([‘d‘,‘e‘]) #list2 = [‘a‘,‘b‘,‘c‘,‘d‘,‘e‘]
Delete
1. del
list = [1,2,3] del list[-1] #list = [1,2]
2. pop()
list = [1,2,3] lastEle = list.pop() # lastEle = 3
Get
1. index(value) - 查找list中的值,并返回其下标
list = [1,2,6] idx = list.index(1) #0 idx = list.index(3) #ValueError: 3 is not in list
以上是关于[python3 - Basic] List的主要内容,如果未能解决你的问题,请参考以下文章
Python3+PCAN-USB基于PCAN-Basic二次开发实现上位机功能
Warning: Permanently added the RSA host key for IP address ‘13.250.177.223‘ to the list of known(代码片
The CPU_ NUM is not specified, you should set CPU_ NUM in the environment variable list。 CPU NUM(代码片