python教學
,函式
,副程式
def HW():
print("Hello World function")
此時只有定義,運行他不會動
HW()
#輸出結果:Hello World function
def HW(name):
print("Hello World", name)
HW("julian")
#輸出結果:Hello World julian
「''」內的字請使用者輸入
I have a 'dog' and its name is 'tony'
I have a 'cat' and its name is 'candy'
輸入 台中市
輸入 清水區
輸入 436
輸出 台中市 清水區 436
def get_location(city, area, zipcode):
location = city + ' ' + area + ' ' + zipcode
return location
def call_student(names):
for name in names:
print("Hi, "+name)
student = ["alan" , "jack" , "rose" , "bonny", "stan"]
call_student(student)
names參數中的星號()會讓python建立一個名字為names的空多元組
def call_num_student(*names):
for name in names:
print("Hi, "+name)
call_num_student("alan" , "jack" , "rose" , "bonny", "stan", "julian")
def sqr(num):
return num*num
提示:while(x%y != 0)
def gcd(x,y):
tmp = 0
while(x%y != 0):
tmp = y
y = x%y
x = tmp
return y
0,1,1,2,3,5,8,13,21,34,55,…
Learn More →
7/22
內容: 很久很久以前,有一個國家叫做「正值國」,這個國家的人做什麼事都非常正直,做人坦蕩蕩。也因此,國家平安和樂、生活富足。
Mar 18, 2025https://github.com/tolgaatam/ColabTurtle
Mar 18, 2025list_a = list(range(1,20,2)) print(list_a) print(list_a[5]) list_a = [1,3,5,7,9,11,13,15,17,19] print(list_a) => [1,3,5,7,9,11,13,15,17,19]
Nov 6, 2022串列
Nov 6, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up