1. 程式人生 > 實用技巧 >4.Gradle構建Spring Boot專案

4.Gradle構建Spring Boot專案

函式:體現了一種封裝的思想,把一個功能封裝在一個函式中,使用的時候直接呼叫這個函式,不用寫重複的程式碼

python函式格式 def 函式名(形式引數):
程式碼塊

Python函式:先定義在使用

用函式寫的一個小dome:計算器

#計算器
def add(a,b):
    """
    加法運算
    :param a: 引數1
    :param b: 引數2
    :return: 返回
    """
    return a + b
def sub(a,b):
    return a - b
def div(a,b):
    return a / b
def Chen(a,b):
    
return a * b #說明文件 help(add) #help + 函式名 print("-----------------------------<<計算器>>-------------------------"); while 1: print("1,加法") print("2,減法") print("3,除法") print("4,乘法") print("5,退出") z = int(input("請選擇你要執行的專案:")) x = int(input("請輸入數字:")) y = int(input("
請輸入數字:")) if z == 1: temp = add(x,y) print("和:%d"%temp) elif z == 2: temp = sub(x,y) print("差:%d"%temp) elif z == 3: temp = div(x,y) print(temp) elif z == 4: temp = Chen(x,y) print(temp) else: break