python的基本数据结构_Python学习笔记——基本数据结构
列表list
List是python的一個內置動態數組對象,它的基本使用方式如下:
shoplist = ['apple', 'mango', 'carrot', 'banana']
'I have', len(shoplist),'items to purchase.'
'These items are:', # Notice the comma at end of the line
for item in shoplist:
print item,
'\nI also have to buy rice.'
shoplist.append('rice')
'My shopping list is now', shoplist
'I will sort my list now'
shoplist.sort()
'Sorted shopping list is', shoplist
'The first item I will buy is', shoplist[0]
olditem = shoplist[0]
del shoplist[0]
'I bought the', olditem
'My shopping list is now', shoplist
元組Tuple
Python的typle通過小括號初始化,是一個只讀對象。不過它的成員具有數組的訪問方式。
zoo = ('wolf', 'elephant', 'penguin')
'Number of animals in the zoo is', len(zoo)
new_zoo = ('monkey', 'dolphin', zoo)
'Number of animals in the new zoo is', len(new_zoo)
'All animals in new zoo are', new_zoo
'Animals brought from old zoo are', new_zoo[2]
'Last animal brought from old zoo is', new_zoo[2][2]
字典dict
Dict是一個查詢式的數據結構,它的基本用法如下:
ab = {????'Swaroop' : 'swaroopch@byteofpython.info',
'Larry' : 'larry@wall.org',
'Matsumoto' : 'matz@ruby-lang.org',
'Spammer' : 'spammer@hotmail.com'
}
"Swaroop's address is %s" % ab['Swaroop']
# Adding a key/value pair
ab['Guido'] = 'guido@python.org'
# Deleting a key/value pair
del ab['Spammer']
'\nThere are %d contacts in the address-book\n' % len(ab)
for name, address in ab.items():
'Contact %s at %s' % (name, address)
if
'Guido'
in ab: # OR ab.has_key('Guido')
"\nGuido's address is %s" % ab['Guido']
python學習筆記五——數據結構
4 . python的數據結構 數據結構是用來存儲數據的邏輯結構,合理使用數據結構才能編寫出優秀的代碼.python提供的幾種內置數據結構——元組.列表.字典和序列.內置數據結構是Python語言的精 ...
Python學習筆記系列——數據結構相關
Python有4種數據結構:列表(list).字典(dictionary).元組(Tuple).集合(set).從最直接的感官上來說,這四種數據結構的區別是:列表中的元素使用方括號括起來,字典和集合是 ...
Python學習筆記(3)--數據結構之列表list
Python的數據結構有三種:列表.元組和字典 列表(list) 定義:list是處理一組有序項目的數據結構,是可變的數據結構. 初始化:[], [1, 3, 7], ['a', 'c'], [1, ...
Python學習筆記(5)--數據結構之字典dict
字典(dict) 定義:鍵值對集合 初始化:{},?{'1' : 'abc', '2' : 'def'} 1.增加:單個數據直接賦值 ?update(dict2) ---把dict2的元素加入到dic ...
Python學習筆記(4)--數據結構之元組tuple
元組(tuple) 定義:tuple和list十分相似,但是tuple是不可變的,即不能修改tuple 初始化:(), ('a', ) , ('a', 'b') ? //當只有一個元素時,需加上逗號, ...
python學習筆記整理——字典
python學習筆記整理 數據結構--字典 無序的 {鍵:值} 對集合 用于查詢的方法 len(d) Return the number of items in the dictionary d. 返 ...
python學習筆記整理——元組tuple
Python 文檔學習筆記2 數據結構--元組和序列 元組 元組在輸出時總是有括號的 元組輸入時可能沒有括號 元組是不可變的 通過分拆(參閱本節后面的內容)或索引訪問(如果是namedtuples,甚 ...
python學習筆記之module &;&; package
個人總結: import module,module就是文件名,導入那個python文件 import package,package就是一個文件夾,導入的文件夾下有一個__init__.py的文件, ...
Python學習筆記,day5
Python學習筆記,day5 一.time & datetime模塊 import本質為將要導入的模塊,先解釋一遍 #_*_coding:utf-8_*_ __author__ = 'Ale ...
隨機推薦
Java中Properties類知識的總結
一.Properties類與配置文件 注意:是一個Map集合,該集合中的鍵值對都是字符串.該集合通常用于對鍵值對形式的配置文件進行操作. 配置文件:將軟件中可變的部分數據可以定義到一個文件中,方便以后 ...
Java完成最簡單的WebService創建及使用(REST方式,Jersey框架)
前言: 一直以來都對WebService感興趣,但因為難以理解WebService到底是什么,所以了解甚少.周二的時候有個跟我關系比較好的同事想要自己寫個WebService的小Demo,希望能夠做成 ...
有關mipmaps
Mipmaps的作用是什么,僅僅是為了使屏幕三角形和紋理三角形的差異變小?有沒有以空間換時間的理念? Mipmaps在生成一系列小的紋理樣本時,?是如何從原始紋理采樣的?即如何生成這些小的紋理樣本.
sed命令實戰
刪除所有的空行,并在每行后面增加一個空行 sed '/^$/d;G' /etc/fstab 將每一行前導的“空白字符”(空格,制表符)刪除 sed 's/^[\t ]*//' file 將文本中的 a ...
Python爬蟲——抓取貼吧帖子
抓取百度貼吧帖子 按照這個學習教程,一步一步寫出來,中間遇到很多的問題,一一列舉 首先, 獲得 標題 和 貼子總數 # -*- coding:utf-8 -*- #!/user/bin/python ...
全選demo
我們處理數據時,最好能夠支持全選操作. 選中之后,進行刪除,或其他處理. 我自己寫了一個demo. 主要功能: 1.點擊全部選中 2.點擊全部取消 3.然后進行獲取選中的id,進行處理 代碼如下: & ...
w3chtml頁面和css書寫規范
http://www.cnblogs.com/Wenwang/archive/2011/09/07/2169881.html
Centos修改默認網卡名
安裝系統后默認的網卡名稱為 enpXX ,修改為熟悉的eth0 1 vi /etc/default/grub GRUB_TIMEOUT=5GRUB_DEFAULT=savedGRUB_DISABLE_ ...
vlc 網頁插件的 使用與控制 API http://www.xuebuyuan.com/2224602.html
不知道vlc 是什么的請百度一下.. vlc 提供了ie瀏覽器的activeX插件和火狐或者chrome的插件,基本上覆蓋了所有瀏覽器,所以有復雜解碼需求的情況下用vlc來解決網頁播放視頻,也是一種沒 ...
洛谷 4525 &;&; 洛谷 4526 【模板】自適應辛普森法
題目:https://www.luogu.org/problemnew/show/P4525 https://www.luogu.org/problemnew/show/P4526 參考:https: ...
總結
以上是生活随笔為你收集整理的python的基本数据结构_Python学习笔记——基本数据结构的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jpa 自定义sql if_跟飞哥学编程
- 下一篇: python基础学习_转行零基础该如何学