Python:变量
# 这是单行注释
print("hello python")
print(3.1415)
print("你是我的,\n优乐美")
"""块注释内容"""
"""
python 是未来程序的发展方向
python 是人工智能,大数据领域最佳的语言
"""
# 变量
name = "张三" # string
age = 58
print("我的名字是",name,"年龄是",age)
pi = 3.1415926 # float
print("pi的值是",pi)
is_weekend = True # boolean
is_weekday = False
print("布尔函数:",is_weekend)
# type函数 :用于得到变量的数据类型
name_type = type(name)
age_type = type(age)
pi_type = type(pi)
print(name_type,age_type,pi_type,type(is_weekend))
# 基本运算符
"""
/ 浮点数除法
// 除法取整
% 取模(余数)
** 幂次方
"""
result1=10/2
print(result1)
result2=9//2
print(result2)
result3=2**4
print(result3)
# input 接受用户输入,将用户输入的字符串保存到变量
mobile_Num=input("请输入你的手机号:") # 返回str
print(mobile_Num)
elec_Num=input("请输入用电量:") # 默认输入为str
charge =float(elec_Num) * 0.48 # 强制类型转换 与c,java等格式不同
print("你的最终电费是:",charge)
charge_tran=str(charge) #强制类型转换为str
charge_tran_type=type(charge_tran)
print(charge_tran_type)
运行结果