# 数据类型主要有整型、布尔型、浮点型、字符型、空值
# 整数类型和浮点数类型
num1 = 10 # 赋值
num2 = 4
num3 = num1 / num2 # 计算结果并赋值
print(num3)
print(type(num1)) # 判断数据类型 type()
print(type(num3))
c = 123_456_789 # 数字的长度过长,可以使用下划线为分隔符,程序运行时,会自动忽略下划线
d = 123456789
print(c, d)
# 字符串 需要用引号引起来,单双引号均可,用于表示文本的数据类型 相同的引号不能嵌套使用
str1 = '子曰:"学而不思则罔,思而不学则殆"'
print(str1)
print(type(str1))
# 单引号和双引号都不能跨行使用,需要跨行要加斜号
s = '锄禾日当午,\
汗滴禾下土。'
print(s)
# 三重引号可以换行,并保留格式
s1 = '''锄禾日当午,
汗滴禾下土'''
# 占位符 %s表示任意字符占位符
b = 'hello %s 你好 %s' % ('tom', 'lili')
print('b=', b)
# %f表示浮点数占位符,可以进位. 小数点后的数字表示要留的位数
b = 'hello %.2f' % 123.456
print('b=', b) # c= hello 123.45
# %d表示整数站数位,直接舍去小数位
c = 'hello %d' % 123.456
print('c=', c) # c= hello 123
a = '我是a'
print('a=%s' % a) # 通过占位符输出变量
# 格式化字符串 在字符串前添加一个f
a = 'i am a'
b = 'i am b'
c = f'hello {a},{b}'
print('c=', c) # c= hello i am a,i am b
# 字符串的赋值:将字符串和数字相乘,会将字符串重复次数并返回
a = 'ah'
a = a * 10
print(a) # 输出:ahahahahahahahahahah
# 布尔型:bool,用于做逻辑判断,有TRUE(相当于1)和FALSE(相当于0)两个值
# 空值:None,表示不存在。是一个特殊常量,不是0,和其他数据比较时永远返回FALSE,有自己的数据类型NoneType
# 输出学生的考试信息
score = '89.5'
name = 'lisa'
sex = 'male'
print('the student\'s name:', name, ',sex:', sex, ',score:', score)
# 打印购物的结算小票
tpri, spri, wpri = 245, 430, 320
t, s, w = 2, 1, 2
ttotal = t * tpri
stotal = spri * s
wtotal = wpri * w
total = ttotal + stotal + wtotal
print('*************************')
print('商品 单价 数量 合计')
print(' T恤 %d' % tpri, ' %d' % t, ' %d' % ttotal)
print(' 球鞋 %d' % spri, ' %d' % s, ' %d' % stotal)
print('网球拍 %d' % wpri, ' %d' % w, ' %d' % wtotal)
print(' ----小计', total)
print('*************************')