Python之内置函数再总结
一.数字相关
1.绝对值:abs(-1)
2.最大最小值:max([1,2,3]) ,min([1,2,3])
3.序列长度:len('abc') , len([1,2,3]) , len((1,2,3))
4.取模:divmod(5,2)//(2,1)
5.乘方:pow(2,3,4)//2**3/4
6.浮点数:round(1)//1.0
二.功能相关
1.函数是否可调用:callable(funcname),注意,funcname变量要定义过
2.类型判断:isinstance(x,list/int)
3.比较:cmp('hello','hello')
4.快速生成序列:(x)range([start,]stop[,step])
三.类型转换
1.int(x)
2.long(x)
3.float(x)
4.complex(x) #复数
5.str(x)
6.list(x)
7.tuple(x) #元组
8.hex(x)
9.oct(x)
10.chr(x) #返回x对应的字符。如chr(65)返回‘A’
11.ord(x) #返回字符对应的ASC数字编号,如ord('A')返回65
四.字符串处理
1.首字母大写:str.capitazlize
'hello'.capitalize()
'Hello'
2.字符串替换:str.replace
'hello'.replace('l','')
'he22o'
3.字符串切割:str.split
'hello'.split('l')
['he', '', 'o']
可以传两个参数,第二个参数为切割次数。
以上三个方法都可以引用String模块,然后用string.xxx的方式进行调用
五.序列处理函数
1.len:序列长度
2.max:序列中最大值
3.min:序列中最小值
4.filter:过滤序列
filter(lambda x:x%2==0, [1,2,3,4,5,6])
结果如下:
[2, 4, 6]
5.zip:并行遍历
>>> name=['jim','tom','lili']
>>> age=[20,30,40]
>>> tel=['','','']
>>> zip(name,age,tel) [('jim', 20, ''), ('tom', 30, ''), ('lili', 40, '')]
注意,如果序列长度不同时,会出现下面的结果:
>>> name=['jim','tom','lili']
>>> age=[20,30,40]
>>> tel=['','']
>>> zip(name,age,tel)
[('jim', 20, ''), ('tom', 30, '')]
6.map:并行遍历,可接受一个function类型的参数
a=[1,3,5]
b=[2,4,6]
map(None,a,b)
[(1,2),(3,4),(5,6)]
map(lambda x,y : x * y,a,b) [2,12,30]
Python之内置函数再总结的更多相关文章
- python之内置函数(一)
一.内置函数一1.内置函数总览 abs() dict() help() min() setattr()all() dir() hex() next() slice() any() divmod() i ...
- python之内置函数(二)与匿名函数、递归函数初识
一.内置函数(二)1.和数据结构相关(24)列表和元祖(2)list:将一个可迭代对象转化成列表(如果是字典,默认将key作为列表的元素).tuple:将一个可迭代对象转化成元组(如果是字典,默认将k ...
- python之内置函数,匿名函数,递归函数
一. 内置函函数 什么是内置函数?就是Python给你提供的,拿来直接用的函数,比如print,input等等.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就 ...
- Python之内置函数
内置函数 python里的内置函数.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数. 分类学习内置函数: 总共 ...
- what's the python之内置函数
what's the 内置函数? 内置函数,内置函数就是python本身定义好的,我们直接拿来就可以用的函数.(python中一共有68中内置函数.) Built-in Functions ...
- python之内置函数与匿名函数
一内置函数 # print(abs(-1)) # print(all([1,2,'a',None])) # print(all([])) #bool值为假的情况:None,空,0,False # # ...
- python之内置函数,匿名函数
什么是内置函数? 就是Python给你提供的,拿来直接用的函数,比如print,input等等.其实就是我们在创建.py的时候python解释器所自动生成的内置的函数,就好比我们之前所学的作用空间 内 ...
- python之内置函数(lambda,sorted,filter,map),递归,二分法
一.lambda匿名函数 为了解决一些简单需求而设计的一句话函数,lambda表示的是匿名函数,不需要用def来声明,一句话就可以声明出一个函数. 语法: 函数名 = lambda 参数 : 返回值 ...
- Python之内置函数一
一:绝对值,abs i = abs(-123) print(i) # 打印结果 123 二:判断真假,all,与any 对于all # 每个元素都为真,才是True # 假,0,None," ...
随机推荐
- C/C++ 错误笔记-如果要释放内存,必须拿到内存的首地址进行释放
例:修改字符串的第三个字母为a #include <stdlib.h> #include <string.h> #include <stdio.h> #pragma ...
- 142. Linked List Cycle II【easy】
142. Linked List Cycle II[easy] Given a linked list, return the node where the cycle begins. If ther ...
- 606. Construct String from Binary Tree 【easy】
606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...
- Mat::operator =
Provides matrix assignment operators. C++: Mat& Mat::operator=(const Mat& m) C++: Mat& M ...
- 关于python ide
关于python ide: 在本机上正经写代码: PyCharm,社区版免费,专业版 $199 每年. 在本机上写几行脚本: ipython 或者 pyipython. 在服务器调试的时候微调代码:v ...
- python3输出指定log信息
问题背景: win10 python xxx.py > c:test.txt 上面这句只能把信息输出到test.txt,但是控制台看不到信息 ########################## ...
- iOS10 获取系统通讯录新方法
#import <ContactsUI/ContactsUI.h> 遵循代理 CNContactPickerDelegate 调用通讯录 如果在iOS10的机器上调用以前的ABPeople ...
- linux list
一篇介绍链表不错的文章: 1. 玩转C链表 2. openwrt使用list 3. 深入分析 Linux 内核链表 https://www.ibm.com/developerworks/cn/linu ...
- PHP 7的一些引人注目的新特性简单介绍
1. ?? 运算符(NULL 合并运算符)把这个放在第一个说是因为我觉得它很有用.用法: ? 1 $a = $_GET['a'] ?? 1; 它相当于: ? 1 2 <?php $a = iss ...
- Leetcode392. Is Subsequence
Description Given a string s and a string t, check if s is subsequence of t. You may assume that the ...