第一章

a = 1
print(type(a))  # <class 'int'> -- 整型

b = 3.1
print(type(b))  # <class 'float'> -- 浮点型

c = True
print(type(c))  # <class 'bool'> -- 布尔型

d = '12345'
print(type(d))  # <class 'str'> -- 字符串

e = [10, 20, 30]
print(type(e))  # <class 'list'> -- 列表

f = (10, 20, 30)
print(type(f))  # <class 'tuple'> -- 元组

h = {10, 20, 30}
print(type(h))  # <class 'set'> -- 集合

g = {'name': 'TOM', 'age': 20}
print(type(g))  # <class 'dict'> -- 字典
%s 字符串
%d 有符号的十进制整数
%f 浮点数
%03d 表示输出的整数显示位数不足以0补全超出当前位数则原样输出
%.2f 表示小数点后显示的小位数

格式化字符串除了%s ,还可以写成 f'{表达式}'

age = 20 
name = 'lazy'
weight = 65.5
student_id = 1

# 我的名字是lazy
print('我的名字是%s' % name)

# 我的学号是0001
print('我的学号是%4d' % student_id)

# 我的体重是65.50公斤
print('我的体重是%.2f公斤' % weight)

# 我的名字是lazy,今年20岁了
print('我的名字是%s,今年%d岁了' % (name, age))

# 我的名字是lazy,明年21岁了
print('我的名字是%s,明年%d岁了' % (name, age + 1))

# 我的名字是lazy,明年21岁了
print(f'我的名字是{name}, 明年{age + 1}岁了')

转义符

换行
制表符
原文地址:https://www.cnblogs.com/laochun/p/14780912.html