目录
A: 86-100, B: 71-85, C: 61-70, D: 0-60 输入一个成绩打印出成绩的等级(要求使用if ... elif)
1.数据类型转换
将浮点型, 字符串转换成整型
print(int(1.2))
print(int('1'))
D:\python\python.exe D:/python/python_code/fjq_var.py
1
1
Process finished with exit code 0
将整数,字符串转成浮点型
print((float(1)))
print(float('1'))
D:\python\python.exe D:/python/python_code/fjq_var.py
1.0
1.0
Process finished with exit code 0
将二进制,八进制,16进制转成10进制
print(int(0b100))
print(int(0o100))
print(int(0x100))
D:\python\python.exe D:/python/python_code/fjq_var.py
4
64
256
Process finished with exit code 0
将10进制转换成,二进制,八进制,16进制
print(bin(4))
print(oct(64))
print(hex(256))
D:\python\python.exe D:/python/python_code/fjq_var.py
0b100
0o100
0x100
Process finished with exit code 0
将字符串转换为字节
print(bytes("封", encoding="UTF-8"))
D:\python\python.exe D:/python/python_code/fjq_var.py
b'\xe5\xb0\x81'
Process finished with exit code 0
将字节转换成字符串
print(str(b'\xe5\xb0\x81', encoding="UTF-8"))
D:\python\python.exe D:/python/python_code/fjq_var.py
封
Process finished with exit code 0
将ascii码转换为字符串
print(chr(98))
D:\python\python.exe D:/python/python_code/fjq_var.py
b
Process finished with exit code 0
将字符串转换成ascii码
print(ord(str('b')))
D:\python\python.exe D:/python/python_code/fjq_var.py
98
Process finished with exit code 0
2.条件控制语句
A: 86-100, B: 71-85, C: 61-70, D: 0-60
输入一个成绩打印出成绩的等级(要求使用if ... elif)
score = 65
if 0 <= score <= 60:
print('d')
elif score <= 70:
print('c')
elif score <= 85:
print('B')
else:
print('A')
D:\python\python.exe D:/python/python_code/fjq_var.py
c
Process finished with exit code 0