第四周課堂筆記 1.標準體重 print((170-80)*0.7) =63 BMI print((60)/(1.7*1.7)) =20.76...... 2.python基本語法: (1)print("Hi,Taiwan!") Hi,Taiwan! (2)if 4>3 : print("four is greater than three!") four is greater than three! (3)x=1 y=Yes print(x) print(y) 1 Yes 如果comment的開頭是#,或者是最後放#,那麼python將會忽略它們 ex: print("ok!") #This is a comment ok! 3.變數 x = 2 # x is of type int x = "no" # x is now of type str print(x) no x = str(5) # x will be '5' y = int(5) # y will be 5 z = float(5) # z will be 5.0 print(x) print(y) print(z) 5 5 5.0 x = 10 y = "good" print(type(x)) print(type(y)) <class 'int'> <class 'str'> x = "abc" # is the same as x = 'abc' 單與雙是一樣的 myvar = "0" my_var = "0" _my_var = "0" myVar = "0" MYVAR = "0" myvar2 = "0" print(myvar) print(my_var) print(_my_var) print(myVar) print(MYVAR) print(myvar2) 0 0 0 0 0 0 x, y, z = “A”, “B”, “C” print(x) print(y) print(z) A B C x=difficult print("python is"+x) python is difficult camel case (駱駝式命名法) Each word, except the first, starts with a capital letter: myVariableName = "Jack" pascal case (帕斯卡命名法) Each word starts with a capital letter: MyVariableName = "Jack" snack case (蛇形命名法) Each word is separated by an underscore character: my_variable_name = "Jack" 資料型態: Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview
{"metaMigratedAt":"2023-06-16T20:47:52.351Z","metaMigratedFrom":"Content","title":"is the same as","breaks":true,"contributors":"[{\"id\":\"07a2a4c8-1664-444d-a7e2-68bed428ef81\",\"add\":1695,\"del\":28}]"}
Expand menu