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 ...
随机推荐
- ImportError: /lib64/libc.so.6: version `GLIBC_2.17' 问题解决
安装最新的TensorFlow(>=1.10)后,载入TensorFlow时提示Glibc版本过低,需要升级到指定版本. ImportError: /lib64/libc.so.6: versi ...
- thinkphp5使用querylist采集图片示例
首先composer引入querylist composer require jaeger/querylist 注意需要php7.0以上版本 <?php namespace app\index\ ...
- thinkphp5加密解密
thinkphp5目前没有提供加密解密类,但是tp3.2中提供了好几种加密解密方法,我们可以吧3.2的这些类拿来使用. 1.将tp3.2中ThinkPHP\Library\Think的Crypt文件夹 ...
- 【补档】Pycharm的一些配置
新建和创建文件就不必说了吧~ 运行这里原本是灰色的,我们点旁边的三角形 点绿色+号,python Name:随便写 Script:选择一个py文件~,然后OK,就可以运行了
- GUI的最终选择 Tkinter(二):Label和Button组件
Label组件 Lable组件是用于界面上输出描述的标签,例如提示用户“您下载的电影含有未成年人限制内容,请满18岁以后点击观看!”,先来上结果图: 在来看下它的代码: from tkinter im ...
- python_魔法方法(五):描述符和定制序列
描述符(property的原理) 描述符(descripto),用一句话来解释,描述符就是某种特殊的类的实例指派给另一个类的属性.那么什么是特殊类型的类呢?就是至少要在这个类中定义__get__(). ...
- Win10创建还原点
Win + E打开任务管理器 右击此电脑,选择属性 单击高级系统设置 选择系统保护 单击系统还原 按照提示操作,OK.
- Java面向对象_Object类
Object类 是类层次结构的根类,每个类都是用Object类作为超类,所有对象(包括数组)都实现这个类的方法.所有类都是Object类的子类. 下面先说两个方法toString()和equals(O ...
- 【Java】在eclipse中使用gradle进行项目构建 入门篇
##Gradle的安装与配置- Gradle 是以 Groovy 语言为基础,面向Java应用为主,基于DSL(领域特定语言)语法的自动化构建工具. 系统环境变量中添加gradle 前往官网下载Com ...
- jsp内置对象和el表达式内置对象误区
未经允许禁止转载... jsp九大内置对象 EL表达式隐含的11个对象 隐含对象名称 描 述 pageContext 对应于JSP页面中的pageContext对象(注意:取的是pageC ...