python基础(五)

目录

1.数据类型转换

将浮点型, 字符串转换成整型

将整数,字符串转成浮点型

将二进制,八进制,16进制转成10进制

将10进制转换成,二进制,八进制,16进制

将字符串转换为字节

将字节转换成字符串

将ascii码转换为字符串

将字符串转换成ascii码

2.条件控制语句

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nemophilistf.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值