1.在字典裡巢狀字典:
呼叫字典裡的字典的方法:(課本例題)
users = , #逗號
『mcurie』: ,
}for username, user_info in users.items(): #對user字典裡的每個字典進行遍歷
print("\nusername: " + username) #以下都是for迴圈的內容
full_name = user_info[『first』] + " " + user_info[『last』]
location = user_info[『location』]
print("\tfull name: " + full_name.title())
print("\tlocation: " + location.title())
2.使用者輸入:input()
函式input()可以讓程式暫停執行,等待使用者輸入一些文字。
例子:(**課本)
message = input("tell me something, and i will repeat it back to you: ")
print(message)
#**第一行是先輸出冒號裡面的話,程式等待使用者輸入,按下回車鍵後繼續執行。
#輸入的內容儲存在變數message
假設寫的提示在一行輸出不完,可以採用:
字串傳入變數
變數+=剩下的字串
新的變數=input(上面的變數)
3.使用input()使得輸入被解讀為字串,輸入的數字不能作為數字而是作為數字的字元使用。
此時令使用過input得到的值為x=『20』#字串資料
將字串變為數值
int(x)
4.求模運算子% (也就是取餘)
5.關於迴圈,for針對的是集合中的每乙個元素,都進行乙個**塊。
而while迴圈,不斷執行,直到不滿足迴圈的條件
while後面緊跟的語句,可以是乙個判斷語句,也可以是乙個標誌變數,標誌為true執行,false停止。
本次位置p107
Python學習手冊(第8章)列表與字典
列表是python中最具靈活性的有序集合物件型別。列表迭代和解析 res c 4 for c in spam res ssss pppp aaaa mmmm res for c in spam res ssss pppp aaaa mmmm list map abs,1,2,0,1,2 1,2,0,...
Python學習手冊 02
物件無非是記憶體中的一部分,包含數值和相關操作的集合。python程式可以分解成模組,語句,表示式,物件。1,程式由模組構成 2,模組包含語句 3,語句包含表示式 4,表示式建立並處理物件 python提高程式設計效率的方法之一 內建型別 像函式,模組,類這樣的程式設計單元也是物件,由def,cla...
python學習手冊 簡記
匹配hello開頭 world結尾字串 中間的任意字元儲存在group中.import re match re.match hello t world hello python world match group 1 python match re.match usr home lumberjack...