| Data Type | Function | 檔案處理 | 模組 |
# comment
# 這個變數用來儲存我的名字
name = 'Simon'
if condition1:
statement1
elif condition2:
statement2
else:
statement3
score = int(input("請輸入成績"))
if score >= 60:
print("成績及格!")
else:
print("成績不及格!")
condition1 or condition2
condition1 and condition2
not condition
score = int(input("請輸入成績"))
if score >= 90:
print("成績 A")
elif score > 70 and score < 90:
print("成績 B")
else:
print("成績 C")
for x in sequence:
statement1
theBeatles = ['John Lennon', 'Paul McCartney', 'Ringo Starr', 'George Harrison']
for i in theBeatles:
print(i)
for i in range(10):
print(i, end=" ")
print() #換行
for i in range(20, 2, -2):
print(i, end=" ")
for i in range(1, 10):
for j in range(1, 10):
if j == 9:
print("\t", i*j) # j == 9時,換行
else:
print("\t", i*j, end = '') # j < 9時,不換行
try:
statement1
except except_name:
statement2
try:
a = int(input())
b = int(input())
print(a/b)
except ZeroDivisionError:
print("Cannot divide by 0!")
except:
print("Wrong input")
else:
print("The answer is " + str(c))
finally:
print("Program finished")