Python必知必会内建函数
Python提供了大量的内置函数共开发者使用,无需我们再自己写某些常用的功能函数,站在前人肩上,避免重复造轮子,提高开发效率。 当你想做一件事,可以先想一下Python是否提供了内置函数。
常用内置函数:
abs(),max(),min(),len(),divmod(),pow(),round(),
callable()测试某个函数是否可调用;
isinstance()
cmp()
range()
xrange()
类型转化函数
type(),int(),long(),float(),complex(),str(),list(),tuple(),hex(),oct(),chr(),ord()
case
>>> a
='123'
>>> a
+12
Traceback
(most recent call last
):
File
"<pyshell#19>", line
1, in <module
>
a
+12
TypeError
: must be
str, not int
>>> int(a
)+12
135
>>>
string函数
,查看帮助
help(str.replace
()),需要导入模块string
str.capitalize
()
str.replace
()
str.split
()
转载请注明原文地址:https://ipadbbs.8miu.com/read-59904.html