python自動化第三天-python

來源:互聯網
上載者:User

標籤:log   複製   ice   char   擷取   清除   多少   上海   too   

一、.列表:

1.序列是Python中最基本的資料結構。序列中的每個元素都分配一個數字 - 它的位置,或索引,第一個索引是0,第二個索引是1,依此類推。

cities=[]

增加

cities.append(‘北京‘)#在列表末尾增加一個元素

cities.insert(0,‘上海‘)#在指定位置增加元素

刪除

cities.pop(0)#刪除指定位置的元素

cities.remove(‘北京‘)#刪除指定的元素

cities.clear() #清除list

del.cities[-1]#刪除指定位置的

修改

print(cities)

cities[1]=‘南京‘#修改的時候如果指定的下標不存在,會報錯

print(cities[0])#查指定位置的

print(cities.index(‘廣州‘))#擷取元素的下標,如果找不到那個元素的話,會報錯

print(cities.count(‘廣州‘))#產看元素在list裡邊出現了多少次

 

my_list = [‘python‘,‘jmeter‘,‘charles‘,‘postman‘]

print(my_list.reverse())#把這個list反轉一下

 

nums = [9,2,34,12,34,457,2342]

nums = [‘b‘,‘f‘,‘e‘,‘z‘,‘g‘,‘h‘]

nums.sort()#升序排列

nums.sort(reverse=True) #降序排列

print(cities+cities2)#合并list

print(cities*3)#複製幾次

words = [‘view‘,‘code‘,‘tools‘,[‘price‘,‘num‘,198,[‘hello‘,‘usa‘,‘吃雞‘]]   ] #二維數組

print(words[-1][-1][1])

print(words[-1][2])

 

python自動化第三天-python

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.