基本語法
型別
Number 數字 String 字串 boolean 布林 List 列表 Tuple 元組 Dictionary 字典 (Map)
列表
list_data = [1, 'string', 3.1, [5, 6, 7]]
print list_data #完整
print list_data[0] #第一個
print list_data[1:3] #第二個到第三個
print list_data[1:] #第二個到最後一個
#getIndex
list_data.index('string') #1
#新增
list_data.append('mouse') #新增在最後
list_data.insert(1,'mouse') #新增在1的位置
#刪除
list_data.remove('string')
#排序
list_data.sort()字典
和 List 用 [] 來包資料不同 Dictionary 是用 {}
讀取使用者的輸入內容
不管使用者輸入什麼,都是字串型別 input()
Number to String
str()
String to Integer
int()
String to float
float()
Boolean
Python 的 True False 都要大寫
&& => and || => or ! => not
要如何宣告 function
前面加 def 後面要加冒號 要縮排
迴圈
參考資料:(https://sites.google.com/site/zsgititit/home/python-cheng-shi-she-ji/python-de-hui-quan-jie-gou)
For
python 是利用縮排,去決定程式的區塊 所以只有指令區的會重複,指令區2的就只有一次
range(5) => 1 ~ 5
range(2,6) => 2~5
range(2,10,2) => 2, 4, 6, 8
while
Last updated
Was this helpful?