names = [1,2,3,"lingyul",' Panyang ']#定义列表, Use []
Print (names)#取列表的值
Print (names[3])#t通过下标取值, Use []
names[0] =' Zhangsan '#列表是可变变量, the values of the list can be modified by subscript
For nameIn Names:#循环列表取值
Print (name)
#列表的增, delete, change, Check
#增
Names.append (' Lingyul011 ')#append给list从最后添加值
#print (the return value of ' append: ', names.append ()) #####??????????????????????
Print (names)
Names.insert (0,' Yuer011 ')#insert是给指定位置添加元素
Print (names)
#删除
Names.pop ()# do not write value default Delete last
Print (names)
Names.pop (4)# Write down the subscript to delete the corresponding underlying value
Print (names)
Print' Before ', names)
Del names[2]# Write down the subscript and delete the corresponding value, you must write the subscript
Print‘********‘)
Print (names)
#del names #删除names, names doesn't exist after Deletion.
Names.remove (' Yuer011 ')#删除元素
Print‘-------‘)
Print (names)
#clear的用法
Dict = {' Name ':' Zara ',' Age ':7};
Print"Start Len:%d"%Len (dict))
Dict.clear ()
Print"End Len:%d"%Len (dict))
b1=[' Ling ',' Dfdf ']
B1.clear ()
Print (b1)
#判断list中是否用某值
Print (names.count (' Yuer '))#查找值在list中出现的次数
NAME1 = [' Yuer ',' Yuer011 ',' Lingyul ']
Print' Yuer 'In Name1)
Print (name1[-1])#下标是-1 represents the last element
Print (name1.index (' Yuer ',0,3))#返回一个元素的下标 can be followed by the start and end positions of the lookup
#两个列表合并
Stus = [' Merger ']
Print (name1+stus)#用 + merge, who writes in front of who is in front
Print' This is extend: ', stus.extend (name1))#extend is to add a list to the previous list
Print (stus)
Print (name1)
Nums = [23,34,21st2,456,35,123456]#按升序排序
Nums.sort ()
Print' Sort is: ', Nums)
#翻转
Print (nums.sort (Reverse=True))
Print' Reverse=true is: ', Nums)
Nums.reverse ()
Print' Reverse is: ', Nums)
List = [1,' Lily ',19.8,[' Niuhanyang ', [' Houyfan ',' sex ']
Print (list[3][1][1])
a1 = [1,2,3]
a2 = [4,5,6]
#a1. extend (a2) #把a2 placed in A1 to form a new A1
A1.append (a2) #把a2 as an element in the a1, the new A1 is a two-dimensional array
Print (a1)
################## #字符串操作
Name =' Hello World '
Import string
Print (string.ascii_letters)#大小写字母 + Numbers
Print (string.ascii_lowercase)#所有的小写字母
Print (string.ascii_uppercase)#所有的大写字母
Print (string.digits)#所有的数字
names=[' DFKJKD ',' SDF ',' Zyz ']
PrintType (NAMES))
PrintSTR (NAMES))#把列表转成字符串
PrintType (NAMES))
Print‘##################‘)
TMP =‘‘
For IIn Names:
TMP = tmp+i+‘,‘
Print' New TMP is: ', Tmp.strip ())
Print' New TMP is: ', Tmp.strip (‘,‘))#去除逗号
Print (name.capitalize ())#首字母大写
Print (name.center (40M‘-‘))
Print (name.endswith (' d '))# See what it ends with #
Print (name.find (' Word ',0,-1))#查找字符串的索引, find the words to return the first occurrence of the index, any coins to return-1.
Print' 123 '. isdigit ())#查看是否是数字
Print' + + '. join (NAMES))#join是用来通过某个字符连接list中的元素, The original string does not change, just returns a new string
#所有字符串的操作方法都不会改变原来字符串的值, just return a new string because the string is not mutable
Print' Mysqlm '. Strip (' M '))#strip默认去除字符串两端的空格和换行, if specified, only the specified string is stripped
Print' MySQL mysql MySQL '. replace (' MySQL ',' Orcal ',2))#替换, Replace (* * Replaced with * * *, replaced several times)
Name1 =' Zcl,py,zyz '
Print (name1)
Print (name1.split (‘,‘))#把字符串转换成列表, Loop judgment, delimited value, If spilt () is not written in parentheses, the default delimiter is a space
New_name=name1.split ( print (new_name.index ( #返回py的下标
print (name1.splitlines ()) #按照换行符分隔
#不引入第三方变量交换a, value of b
A = 1
B =2
a, b = b,a
print (" b is: ', b)
a=a+b
b=a-b
a=a-b
print ( ' b is: ', b)
Name =' CiCi Yuer lingyul '
Print' CiCi 'InchName#判断一个元素是否在list里面
Print' yuer011 'Not inName
Print' yuer011 'Is' Yuer011 ')
name1=' yuer011 '#地址相同所以name1 equals name2 and the run result is true
PrintID (name1))
Name2=' yuer011 '
PrintID (name2))
Print (name1Is Name2)
names=[' AAA ',' BBB ']#地址不同所以names is not equal to name3 and the result is false
name3=[' AAA ',' BBB ']
Print (namesIs Name3)
Print' Names is ',ID (NAMES))
Print' Name3 is ',ID (name3))
Count=0
Names =' CiCi Yuer lingyul '
ForNameIn Names: #for循环是循环字符串里面的每一个元素
print ( name)
print ( ' count: ', count ')
Count+=1
for i in " Span style= "color: #000080" >range (len (names))
print ( name[i]) #通过下标取值
Name4 = ' CiCi '
print ([0])
Python Automation Test ARIES-WEEK3 list + string