Python 语言在定义变量时,不需要指定变量的数据类型. Python 程序会根据变量值,自动实现变量类型确定.
举例创建一个整型变量
# 整型数据 int (integer)
num1 = 999
# print(f'num1 = {num1}') 输出的固定格式. f的作用: f 全称 format (格式化),特点就是在单引号字符串中能够书写{},大括号中可以放入 '变量名'.
print(f'num1 = {num1}, type(num1) = {type(num1)}')
可在编译器内运行以下代码,理解上述意思。
num1 = 999
print(f'num1 = {num1}, type(num1) = {type(num1)}')
print('num1 = {num1}, type(num1) = {type(num1)}')