python_69_内置函数1
#abs()取绝对值
'''
all(iterable)
Return True if all elements of the iterable are true (or if the iterable is empty).
'''
print(all([0,9,-8,'a']))
print(all([9,-8,'a']))
'''
any(iterable)
Return True if any element of the iterable is true. If the iterable is empty, return False.
'''
print(any([0,9,-8,'a']))
print(any([])) # ascii(object)
# As repr(), return a string containing a printable representation of an object,
# but escape the non-ASCII characters in the string returned by repr() using \x, \u or \U escapes.
a=ascii(['a',1,'汉子'])
print(a,[a])
print(type(a))#格式是字符串
'''
bin(x)
Convert an integer number to a binary string prefixed with “0b”.
'''
print(bin(3))
#布尔bool
print(bool(0))
print(bool(1))
print(bool([]))
#byte
a=bytes('abc',encoding='utf-8')
print(a.capitalize(),a)#字符串不可以修改,二进制的字节格式也不可以修改,要想修改只能生成新的
#bytearray字节的数组可以被修改
b=bytearray('abc',encoding='utf-8')
print(b[0],b[2])
#b[0]='B'#错误。必须以字节形式修改
b[0]=65
b[1]=66
b[2]=67
print(b)
'''
callable(object)判断是否可以被调用
'''
print(callable([]))
def diaoyong():pass
print(callable(diaoyong))#函数和类都可调用
# chr(i),i必须是数字,将数字转为ascll码字符
print(chr(67))
#ord与chr相反
print(ord('C'))
#compile()
code1='for i in range(10):print(i)'
exec(code1)#以下两行程序同等此行
# c=compile(code1,'','exec')#exec将字符串编码可执行的程序
# exec(c)
#print(c),c是内存中的数据对象
code2='1+3/2*6'
print(eval(code2)) #以下两行程序同等此行
'''
c=compile(code2,'','eval')
eval(c)#,适合字符串变字典,以及加减乘除类,不适合语句类,比如for循环,这样的用exec
'''
code3='''
import time
def consumer(name):
print("%s 准备吃包子啦!" %name)
while True:
baozi = yield
print("包子[%s]来了,被[%s]吃了!" %(baozi,name))
c=consumer('猪小芳')
c.__next__()
b1='韭菜馅'
'''
exec(code3)#以下两行程序同等此行
# py_obj=compile(code3,'err.log','exec')#编译过程中出的错会写到err.log中,写不写无所谓,不好使
# exec(py_obj)
#complex复数
print(complex('1+2j')+complex('2+2j'))
#dict字典
print(dict())#生成字典
#dir查看使用方法
a={}
b=()
print(dir(a))
print(dir(b))
#divmod(a,b),return商和余数
print(divmod(6,4))
#匿名函数,用完就释放
(lambda n:print(n*n))(5)#一种传递参数的方法
calc=lambda n:print(n*n)
calc(10)
# calc2=lambda x:for i in range(x):print(i)#处理不了复杂的,可以处理三元运算这种简单的
calc3=lambda n:3 if n<4 else n
print(calc3(5))
#lambda可与filter过滤器结合使用
res=filter(lambda n:n>5,range(10))
print(res)#迭代器
for i in res:
print(i,end='\t')
print('>>>>>>>>>分隔符1')
#lambda可与map结合使用
res=map(lambda n:n*2,range(10))#等价于[i*2 for i in range(10)],[lambda n:n*2 for i in range(10)]
print(res)#迭代器
for i in res:
print(i,end='\t') print('>>>>>>>>>分隔符1')
import functools
print(functools.reduce(lambda x,y:x*y,range(1,10)))#阶乘
print(functools.reduce(lambda x,y:x+y,range(10)))#累加和
#不可变集合,就和元组似的
a=frozenset([1,4,333,212,33,33,12,4])
print(a)
#返回本文件程序的所有全局变量及值
print(globals())
'''
hash(object)哈希:每个数据对应一个数字映射,便于查找
Return the hash value of the object (if it has one).Hash values are integers.
They are used to quickly compare dictionary keys during a dictionary lookup.
Numeric values that compare equal have the same hash value
(even if they are of different types, as is the case for 1 and 1.0).
'''
print(hash('熊羚羽'))
print(hash('韩江桦'))
print(hash('俞莎莎'))
print(hash('熊羚羽'))#与第一个对应的映射是相同的
python_69_内置函数1的更多相关文章
- Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数
11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...
- Oracle内置函数:时间函数,转换函数,字符串函数,数值函数,替换函数
dual单行单列的隐藏表,看不见 但是可以用,经常用来调内置函数.不用新建表 时间函数 sysdate 系统当前时间 add_months 作用:对日期的月份进行加减 写法:add_months(日期 ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- DAY5 python内置函数+验证码实例
内置函数 用验证码作为实例 字符串和字节的转换 字符串到字节 字节到字符串
- python之常用内置函数
python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__&quo ...
- freemarker内置函数和用法
原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...
- set、def、lambda、内置函数、文件操作
set : 无序,不重复,可以嵌套 .add (添加元素) .update(接收可迭代对象)---等于批量 添加 .diffrents()两个集合不同差 .sysmmetric difference( ...
- SQL Server 内置函数、临时对象、流程控制
SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...
- Python-Day3知识点——深浅拷贝、函数基本定义、内置函数
一.深浅拷贝 import copy #浅拷贝 n1={'k1':'wu','k2':123,'k3':['carl',852]} n2=n1 n3=copy.copy(n1) print(id(n1 ...
随机推荐
- windows severs 2008r2 180天激活
无需破解:Windows Server 2008 R2 至少免费使用 900天 1.首先安装后,有一个180天的试用期. 2.在180天试用期即将结束时,使用下面的评估序列号激活Svr 2008 R2 ...
- Pycharm自动部署项目
Pycharm自动部署项目 大家好呀,又有几天不见各位了.断更了几天,给大家说声抱歉.清明节大家都挺忙的,有扫墓祭祖的,也有趁小长假去游玩的. 所以,在节后,更新也会照常进行,继续给大家分享本人的一些 ...
- 《H5+移动应用实战开发》已出版
<H5+移动应用实战开发>终于出版了,最近在忙着Vue和Webpack相关的前端书籍写稿.本书面向的读者为:从后端转前端,或零基础开始学习移动端开发的人.前后端完全分离的开发方式越来越成为 ...
- Java start和run启动线程的区别
我们知道,我们通过调用线程的start方法启动一个线程,那么,我们可以直接调用run方法来启动一个线程吗? 先看下面一段代码: public class Test { public static vo ...
- Luogu P3223 [HNOI2012]排队 组合
本来做了一道 P4901 排队 后来发现自己做错题了...到也都是数学qwq 这题最恶心的就是两只(雾)老师. 那我们分类讨论: 1.两个老师之间是男生: $ A(n,n)*A(n+1,2)*A(n ...
- C# String.Format方法
一.定义String.Format是将指定的 String类型的数据中的每个格式项替换为相应对象的值的文本等效项. 如: (1)string p1 = "Jackie";strin ...
- Swift-字符串
1.字符串的遍历 //NSString 不支持一下字符串的遍历 let str = "我要飞的更高" for c in str.characters{ print(c) } 2.字 ...
- vue resource patch方法的传递数据 form data 为 [object Object]
今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...
- 【干货】Html与CSS入门学习笔记12-14【完】
十二.HTML5标记 现代HTML html5新增的元素:header nav footer aside section article time 这些新增元素使页面结构更清晰,取代<div i ...
- 基于python3.6的如何爬取百度地图
先前参考了其他的代码,大多数是python2.7写的,而3.6用的类库以及规则有了很大的变动,所以自己写了一个这样的代码,供给大家参考. def get_station(i): station=[] ...