Python for Developers 入门
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 for Developers 入门