Files
2026-05-06 11:21:42 +08:00

28 lines
671 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 什么是浮点数?
# 浮点数是用来表示实数(包含小数点的数)的数据类型。在 Python 中,浮点类型用 float 表示。
pi = 3.1415926
temperature = -10.5
salary = 5000.00
scientific = 6.02e23 # 科学计数法:6.02 × 10²³
# 类型转换
# 使用float()函数进行类型转换
float_form_init = float(40)
print(float_form_init) # 40.0
float_form_str = float("99")
print(float_form_str) # 3.14
float_form_bool = float(True)
print(float_form_bool) # 1.0
float_form_false = float(False)
print(float_form_false) # 0.0
# 除法运算会产生浮点数
result1 = 10 / 2
print(result1) # 5.0
result2 = 7 / 2
print(result2) # 3.5