python基础--函数1(abs,max,min,int,str,float,bool,bytes)

1.内容简介:

本节介绍常用的函数,包括abs,max,min,int,str,float,bool,bytes等。

2. 举例:

测试代码:

#abs,max,min,int,str,float,bool,bytes
>>> abs(-10)
10
>>> max(1,6,3)
6
>>> min(1,6,3)
1
>>> int(r)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'r' is not defined
>>> int(10)
10
>>> str(q)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'q' is not defined
>>> str(99)
'99'
>>> float(10.1)
10.1
>>> bool(5)
True
>>> bool(-1)
True
>>> bool(5>5)
False
>>> bytes(qwe)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'qwe' is not defined
>>> bytes('qw')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument without an encoding
>>> bytes('qq', encoding='utf-8')
b'qq'
>>>


   

说明:

1. 如果执行函数错误,请根据错误信息进行排查 。

2. 函数说明:

常用函数总结
函数名功能说明
abs获取绝对值

max

获取最大值
min获取最小值
int 获取int型数据
str获取str型数据
float获取float型数据
bool获取bool值,返回True or False
bytes获取字节串

(1)bytes 是 Python 3.x 新增的类型;

(2)以b为前缀,例如b'abc'


当程序员,基础知识要扎实。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

liranke

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

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

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

打赏作者

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

抵扣说明:

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

余额充值