# 3/7筆記
# 變數
常用型態:
| Text Type: | Numeric Types: | Boolean Type |
| -------- | -------- | -------- |
| str | int, float, complex | bool |
type()--找出資料型態
若型態不一,則無法執行/錯誤
E.G:X為int Y為str
無法執行X+Y 因型態不一
因此需要加以"宣告"
E.G:x=str(3)---->x為"3"
y=int(3)---->y等於3
z=float(3)---->z為3.0
# 註解
在程式碼前加上#
在#後的程式碼後不會執行
# 指定變數
指定多個變數
E.G:x,y,z="water","dirt","land"
print(x) #x為water
print(y) #y為dirt
print(z) #z為land
# 輸出串接
在同型態為前提,執行串接
E.G:x="you"
print("how are "+x) #同為str
# 串列
E.G:thislist=["apple","banana","cherry"]
將apple,banana,cherry放到串列中
LEN能求出串列中的項目數
E.G:thislist=["apple","banana","cherry"]
print(len(thislist))
sorted能將串列中的數字由小到大排列
E.G:list=[2,3,7,0,22,13]
print(sorted(list))
atppend能直接增加項目到原串列後面
E.G:list["apple","banana","cherry"]
list.append("orange")
print(list)
insert則是可以決定項目插入的位置
E.G:list["apple","banana","cherry"]
list.insert(2,"orange")
print(list)
extend能使兩個串列合併
E.G:thislist=["apple","banana","cherry"]
tropical=["mango","pineapple","papaya"]
thislist.extend(tropical)
print(thislist)
remove能移除不想要的項目
E.G:thislist=["apple","banana","cherry"]
thislist.remove("banana")
print(thislist)
clear清空串列中所有項目
E.G:thislist=["apple","banana","cherry"]
thislist.clear()
print(thislist)
# 字典
dic能得出想尋找的值
E.G:dic=("apple":40,"banana":60,"cherry":80)
print(dic["apple"])