python之内置函数与匿名函数
一内置函数
# print(abs(-1))
# print(all([1,2,'a',None]))
# print(all([]))
#bool值为假的情况:None,空,0,False
# # print(any([]))
# print(any([' ',None,False])) #True
# print(any(['',None,False])) #False
# print(any(['',None,False,1])) #True
#bin,oct,hex
# print(bin(10))
# print(oct(10))
# print(hex(10))
#bytes
#unicode----encode----->bytes
# print('hello'.encode('utf-8'))
# print(bytes('hello',encoding='utf-8'))
#callable
# print(callable(bytes))
# print(callable(abs))
#chr,ord
# print(chr(65))
# print(chr(90))
# print(ord('#'))
#内置函数,又被称为工厂函数
# int
# x=1 #x=int(1)
# print(type(x))
# x=int(2)
complex
float
str
list
tuple
dict
set #可变集合
frozenset #不可变集合
# s={1,2,3,4} #s=set({1,2,3,4})
# print(type(s))
#
# s1=frozenset({1,2,3,4})
# print(type(s1))
#dir
# import sys
# # sys.path
# # sys.argv
# print(dir(sys))
#divmod
# print(divmod(10,3))
# print(divmod(102,20))
#enumerate
# l=['a','b','c']
# res=enumerate(l)
# for i in res:
# print(i)
# for index,item in enumerate(l):
# print(index,item)
#globals,locals #查看全局作用域和局部作用域
# print(globals())
#hash
# print(hash('abcdefg123'))
# print(hash('abcdefg123'))
# print(hash('abcdefg123'))
# print(hash('abcdefg123'))
#给函数加文档解释,用到单引号,双引号,三引号
def func():
# '''
# test function
# :return:
# '''
pass # print(help(func)) #id:是python解释器实现的功能,只是反映了变量在内存的地址
#但并不是真实的内存地址
# x=1
# print(id(x)) # def func():pass
# print(id(func))
# print(func) #isinstance
# x=1
# print(type(x) is int)
# print(isinstance(x,int)) #x=int(1) #迭代器
iter
next #len
#max
# print(max([1,2,3,10]))
# print(max(['a','b']))
# print(min([1,2,3,10])) #pow
# print(pow(3,2,2)) #3**2%2 #range # #repr,str
# print(type(str(1)))
# print(type(repr(1))) #reversed
# l=[1,'a',2,'c']
# print(list(reversed(l)))
# print(l) #slice
# l=[1,2,3,4,5,6]
# print(l[0:4:2])
#
# s=slice(0,4,2)
# print(l[s]) #sorted
# l=[1,10,4,3,-1]
# print(sorted(l,reverse=True)) #sum
# print(sum([1, 2,3]))
#
# print(sum(i for i in range(10))) #vars
# import m1
# print(vars(m1) == m1.__dict__) #zip:拉链
# s='hellosssssssssssssssss'
# l=[1,2,3,4,5]
#
# print(list(zip(s,l))) #__import__
import sys # m_name=input('module>>: ')
# if m_name == 'sys':
# m=__import__(m_name)
# print(m)
# print(m.path)
#
# sys=__import__('sys')
# print(sys) #round
print(round(3.565,2))
print(round(3.555,2)) #filter,map,reduce 重点
#max min sorted #面向对象
object
super
# __dict__
isinstance
issubclass classmethod
staticmethod
property
delattr
hasattr
setattr
getattr #了解
compile
eval
exec
二匿名函数
def func(x,y,z=1):
return x+y+z
# print(func)
# print(func(1,2,3))
#匿名函数:1. 没有名字 2:函数体自带return
# print(lambda x,y,z=1:x+y+z)
f=lambda x,y,z=1:x+y+z
print(f)
print(f(1,2,3))
# x=1
# 1
# print(x)
# print(1)
#匿名函数的应用场景:
#应用于一次性的场景,临时使用
python之内置函数与匿名函数的更多相关文章
- python之内置函数,匿名函数
什么是内置函数? 就是Python给你提供的,拿来直接用的函数,比如print,input等等.其实就是我们在创建.py的时候python解释器所自动生成的内置的函数,就好比我们之前所学的作用空间 内 ...
- python之路——内置函数和匿名函数
阅读目录 楔子 内置函数 匿名函数 本章小结 楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们 ...
- python——内置函数和匿名函数
内置函数 接下来,我们就一起来看看python里的内置函数.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数.这 ...
- python(day16)内置函数,匿名函数
# add = lambda x,y:x+y # print(add(1,2)) # dic={'k1':10,'k2':100,'k3':30} # def func(key): # return ...
- Py修行路 python基础 (十三)匿名函数 与 内置函数
一.匿名函数 1.定义: 匿名函数顾名思义就是指:是指一类无需定义标识符(函数名)的函数或子程序. 2.语法格式:lambda 参数:表达式 lambda语句中,开头先写关键字lambda,冒号前是 ...
- python 内置函数和匿名函数
内置函数 截止到python版本3.6.2,现在python一共为我们提供了68个内置函数. Built-in Functions abs() dict() help() min() ...
- python 07篇 内置函数和匿名函数
一.内置函数 # 下面这些要掌握 # len type id print input open # round min max filter map zip exec eval print(all([ ...
- Python_内置函数和匿名函数
楔子 在讲新知识之前,我们先来复习复习函数的基础知识. 问:函数怎么调用? 函数名() 如果你们这么说...那你们就对了!好了记住这个事儿别给忘记了,咱们继续谈下一话题... 来你们在自己的环境里打印 ...
- Python中的高阶函数与匿名函数
Python中的高阶函数与匿名函数 高阶函数 高阶函数就是把函数当做参数传递的一种函数.其与C#中的委托有点相似,个人认为. def add(x,y,f): return f( x)+ f( y) p ...
- Python高阶函数和匿名函数
高阶函数:就是把函数当成参数传递的一种函数:例如 注解: 1.调用add函数,分别执行abs(-8)和abs(11),分别计算出他们的值 2.最后在做和运算 map()函数 python内置的一个高阶 ...
随机推荐
- CentOS6.5安装kafka-2.10-0.8.2(单机)
1.下载 地址:https://kafka.apache.org/downloads 本文中下载版本:kafka_2.10-0.8.2.2.tgz 2.安装 安装目录:/usr/local [root ...
- CentOS6.5安装RHive
1.安装RServe软件包(各个节点都要安装) [root@Hadoop-NN-01 mysofts] # R CMD INSTALL Rserve_1.7-2.tar.gz 2.设置环境变量 [ro ...
- Mybatis select、insert、update、delete 增删改查操作
MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBatis 可以使用简单的XML ...
- Serveral effective linux commands
1. 统计当前文件夹下文件个数(不包括子目录下文件): $ ls -l | grep "^-" | wc -l 2. 统计当前文件夹下文件个数(包括子目录下文件): $ ls -l ...
- MyEclipse10中文乱码
1 进入window->preferences general->content types,可以设置Text对应的default encoding值为UTF-8或为空,然后点击updat ...
- JavaScript--定时器setTimeout()、clearTimeout(var param)和setInterval()、clearInterval(var param)
1.setTimeout().clearTimeout(var param) setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,只调用一次 clearTimeout() 方法可取 ...
- 取n到m行
取n到m行 . select top m * from tablename where id not in (select top n id from tablename order by id as ...
- 【2017-03-02】C#集合,结构体,枚举
集合 集合与数组的区别 数组:同一类型,固定长度 集合:不同类型,不固定长度 使用集合前需要: 引用命名空间:using System.Collections; 1.普通集合 定义: Arra ...
- 解决 samba 服务器 windows 多重连接
samba连接,用户名密码均正确.失败提示:不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接. 事实上,这个不是samba的限制.是Windows的限制. 在打开存在public = ...
- MongoDB在windows上的安装
D:\MongoDB\Server\4.0\bin 下载地址:https://www.mongodb.com/download-center/community 中文教程:http://www.run ...