習題6
#f"{}"格式化 "f-string"
type_of_people = 10
x = f"there are types of people."
binary = "binary"
do_not = "don't"
y = f"those who know and those who ."
# 注意:f"{}"字串的形式,我把變數放置到{}此位置
print(x)
print(y)
print(f"i said: ")
print(f"i also said ''")
#注意: f"{}"中已經可以直接放置變數 若在{}兩側再加單引號『{}』 則列印結果仍然是''
hilarious = false
joke_evaluation = "isn't that joke so funny {}!"
print(joke_evaluation.format(hilarious))
#注意:str.format()函式呼叫元素 即上例中$hilarious的值 填充進{}
w = "this is the left side of..."
e = "a string with a right side."
print(w + e)
#列印w + e的輸出沒有空格 則原封不動是兩個變數值的向量和
習題6主要演練還是格式化字串
f"{}" 格式化字串變數,將變數填位到這個{}位置
不止乙個填充位的話依次{}需要格式化的變數位置
也可以使用joke_evaluation.format(varsome)對{}直接進行格式化。
列印w + e的輸出沒有空格 則原封不動是兩個變數值的向量和
執行結果如下:
there are 10 types of people.
those who know binary and those who don't.
i said: there are 10 types of people.
i also said 'those who know binary and those who don't.'
isn't that joke so funny false!
this is the left side of...a string with a right side.
《「笨辦法」學python3》Ex 3
在python3中進行數字計算和真值判斷.與c 相同,統計我的雞 print i will now count my chickens 母雞25 30 6 30 print hens 25 30 6 公雞100 25 3 4 97 print roosters 100 25 3 4 統計我的蛋 pr...
笨辦法學Python3 ex44 學習筆記
第44個練習是關於繼承。第乙個例子講的是隱式繼承,什麼是隱式繼承呢?簡單地說,當a類中存在的特性或方法x,而b類中沒有定義,直接從a類中繼承得來,這種方式得繼承就是隱式繼承。如下面得 ex44a.py class parent object defimplicit self print parent...
《「笨辦法」學python3》附錄 Ex 0
本科非計算機專業,基本零基0礎 python3 入門。筆記會概述每個練習的核心內容,分享遇見的問題以及解決方案,歡迎各位批評指正。zed強調命令列練習,命令列鏈結程式和計算機,使程式可以控制計算機。計算機中,shell是乙個殼,是指 提供使用者使用介面的軟體 基本shell分成兩類 1.圖形介面 微...