python3測試工具開發快速入門教程3序列小結與文字處理
預計本章簡稿完成日期: 2018-07-18
變數與賦值
自己實現求最大值。
程式碼:
#!python #!/usr/bin/env python3 # -*- coding: utf-8 -*- # Author:xurongzhong#126.com wechat:pythontesting qq:37391319 # 技術支援 釘釘群:21745728(可以加釘釘pythontesting邀請加入) # qq群:144081101 591302926567351477 # CreateDate: 2018-6-12 # mymax2.py # Write max function without built-in max(). def mymax2(x, y): """Return larger of x and y.""" largest_so_far = x if y > largest_so_far: largest_so_far = y return largest_so_far def main(): print("MyMax: Enter two values to find the larger.") first = float(input("First value: ")) second = float(input("Second value: ")) print("The larger value is", mymax2(first, second)) main()
執行:
#!python $ python3 mymax2.py MyMax: Enter two values to find the larger. First value: 3 Second value: 89 The larger value is 89.0
注意賦值是=,判斷是否等於是==。
python的基礎資料型別有bool、float、int、str