Python 入門(開發者向)
Jasmin Ludolf
Senior Data Science Content Developer
$$
$$
$$
new_ingredient_quantity = 1.5
$$
$$
is_in_stock = True
is_in_stock = False
type()
字串
ingredient_name = "tomatoes"print(type(ingredient_name))
<class 'str'>
整數
ingredient_quantity = 2print(type(ingredient_quantity))
<class 'int'>
浮點數
new_ingredient_quantity = 1.5print(type(new_ingredient_quantity))
<class 'float'>
布林值
is_in_stock = Trueprint(type(is_in_stock))
<class 'bool'>
type() 辨識型別
算術運算子:
+ 加法- 減法* 乘法/ 除法數值:
print(2 + 1.5)
3.5
字串:
+ 和 * 可用"Hi" + "There" = "HiThere"
"Hi" * 3 = "HiHiHi"
Python 入門(開發者向)