日期 | 活動內容 |
---|---|
10/08 | 環境建置、資料型態跟一些有的沒的 |
10/15 | json、import、讀寫檔 |
10/22 | 判斷式結構、迴圈、函式 |
10/29 | 預備週 |
11/05 | 考試週 |
11/12 | 封包、requests、API、DOM解析 |
11/19 | 以下待定 |
Python是一種廣泛使用的直譯式、進階編程、通用型程式語言,由吉多·范羅蘇姆創造,第一版釋出於1991年。可以視之為一種改良的LISP。
python -V
python -V
pip -V
型別(type) | 值(value) |
---|---|
int | 1, 0, -1, -2 |
float | 1.0, 1.5, -2.3 |
string | "Hello world!" |
list | [1, 2, "早安", 3.0] |
dict | {"key": "value", 1: 234} |
bool | True, False |
something_ghost = input("輸入一些什麼鬼都行:") print(something_ghost)
type(something_ghost)
a = int(something_ghost) type(a)
print("高", "大", sep='科', end='\n資研社')
運算子(operator) | 這啥 | 範例 | 結果 |
---|---|---|---|
+ | 加法 | 3 + 2 | 5 |
- | 減法 | 3 - 2 | 1 |
* | 乘法 | 3 * 2 | 6 |
/ | 除法 | 3 / 2 | 1.5 |
% | 除法取餘數 | 3 % 2 | 1 |
// | 除法商取整數 | 3 // 2 | 1 |
** | 次方 | 3 ** 2 | 9 |
運算子(operator) | 這啥 | 範例 | 結果 |
---|---|---|---|
or | 或 | (2 > 1) or (1 < 0) | True |
and | 及 | (2 > 1) and (1 < 0) | False |
not | 非 | not (1 < 0) | True |
運算子(operator) | 這啥 | 範例 | 結果 |
---|---|---|---|
> | 大於 | 3 > 2 | True |
< | 小於 | -1 < 2.5 | True |
== | 等於 | 3 == 2.99 | False |
>= | 大於等於 | 1 >= 1.0 | True |
<= | 小於等於 | 2 <= -9 | False |
!= | 不等於 | 3 != 2.99 | True |
1 == 1 # -> True 1 != 1 # -> False [] is [] # -> False (不同物件) [] is not [] # -> True a = b = [] a is b # -> True (相同物件) a is not b # -> False
empty = [] banknote = [100, 200, 500, 1000] name = ['銀色的鮮奶', '橙色的鮮奶', '綠色的鮮奶'] mixed = [1, 0.9, 'cat', [1,2], 'fruit'] print (empty, banknote, name, mixed)
運算 | 描述 |
---|---|
s[i] = x | 將第i個物件換成X |
s[i:j] | 選取s的第i個到第j-1個物件 |
del s[i:j] | 刪除s的第i個到第j-1個物件 |
s[i:j:k] | 選取s的第i個到第j-1且間隔為k的物件 |
運算 | 描述 |
---|---|
x in s | 物件x是不是在s中,若是為True,否為False |
x not in s | 物件x不在s中,若是為True,否為False |
s + t | 將s與t接起來 |
len(s) | s的物件個數 |
min(s) | s的最小值 |
max(s) | s的最大值 |
函式名 | 描述 |
---|---|
append(object) | 在末端加入物件 |
insert(index, object) | 依指定索引值插入物件 |
pop(index) | 從list移除物件(預設為最後一個) |
index(object) | 找出物件的索引值 |
函式名 | 描述 |
---|---|
remove(object) | 移除list中的第一個物件 |
reverse() | 將list中的所有物件反向 |
sort() | 將list中的物件做排序 |
count(object) | 計算物件在list中出現的次數 |
clear() | 將list清空 |
a = [1, 2, 3] a.append(4)
name = ('Jonathan', 'Joseph', 'Jotaro', 'Josuke', 'Giorno' ) print(name)
name = ('Jonathan', 'Joseph', 'Jotaro', 'Josuke', 'Giorno' ) name = name + ('Jolyne',) print(name)
為什麼要加逗號
name = ('Jonathan', 'Joseph', 'Jotaro', 'Josuke', 'Giorno', 'Jolyne' ) name = name + ('Jolyne') print(name)
grade = { 'Chinese': 98, 'English': 65, }
subject = ['Chinese', 'English', 'Math', 'History', 'Physics', 'Chemistry']
score = [98, 65, 87, 77, 50, 88]
score_index = subject.index('Physics')
print("Physics score =", score[score_index])
grade = { 'Chinese': 98, 'English': 65, 'Math': 87, 'History': 77, 'Physics': 50, 'Chemistry': 88 } print("Physics score =", grade['Physics'])
grade['Math'] = 100 print(grade)
grade['English'] = 95 print(grade)
a = { 0: 'hi!', 'Apple': 12.3, } print(a) print(a['Apple'])
str = "road roller" print(str) print(str[1])