string = "String"
for s in string:
print(s)
# "String" => "S","t","r","i","n","g"
跟list很像,但差別在於 初始值不能改變
t1 = tuple()
t2 = ()
print(t1)
print(t2)
t = (1,2,3)
t[0] = 5
一個對應一個,Key對應到Value
像字典一樣,一個名詞對應到一個解釋
Learn More →
d = {
"a":"abc",
"b":"bcd"
}
print(d)
print(d['a'])
print(d['b'])
要用到的東西一定要在字典內,否則會產生KeyError錯誤
d = {
"a":"abc",
"b":"bcd",
"ab":"1231213",
5: "這是五"
}
print(d)
print(d['ab'])
print(d['a'])
print(d['b'])
print(d[5])
# 只會印出完全一樣的key(鍵)的值,
# 會找完全一樣的Key來做對應
# dict的key中可以同時有數字、字串
d = {
"cat":"小貓",
"dog":"小狗",
"bird":"小鳥",
"fish":"魚",
}
print(d['cat'])
for i in d:
print("key:", i, " value:", d[i])
Set跟Dict都是用大括號{},
特點在於,會把重複的東西自動去除
s = set()
s = {1,2,3,1,2,3,"1","2","3"}
print(s)
去除重複的資料
l = ["小明","小華","小東","小明"]
print(l)
print(set(l)) # 把list轉成set
原本電腦中的設定有多個python macOS內建python3、有透過brew、IDLE、PyCharm安裝的 https://developer.apple.com/forums/thread/680222 後來全都都刪除 /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /usr/local/ bin/python3 /usr/bin/python3
Aug 24, 2022松崗 作者黃建庭 2-15 bit位移 A = 5 << 2 2-16 運算子優先順序 1 ()[]{}
Aug 7, 2021def function 要先定義,定義完要呼叫才會執行 def test(): print("123") test() 因為python是直譯的關係,如果先呼叫 會找不到定義
Jul 28, 2021code = { 'A':"10", 'B':"11", 'C':"12", 'D':"13", 'E':"14", 'F':"15", 'G':"16", 'H':"17", 'I':"34",
Jul 12, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up