本节内容:

一之前课程回顾:
在书写代码的时候,先写简单的逻辑在写复杂的逻辑。
概念梳理:
1、函数在传递实参的时候是传递的是引用而不是从内存中重新赋相同值给形参。
比如:
 def test(x):
x.append() list_1=[,,,,]
test(list_1)
print(list_1)
[, , , , ]

2、函数名带圆括号和不带圆括号。
 def test(x):
x.append() list_1=[,,,,]
a=test(list_1)
b=test
print(list_1)
print(b,a) [, , , , ]
<function test at 0x027117C8> None

函数名带圆括号是函数的调用,由于函数test没有返回值,所以输出None,而函数名代表的是函数体,上面是把函数体test赋值给b。
所以可以直接执行b函数和执行test函数是一样的。
 def test(x):
x.append()
return 'b' list_1=[,,,,]
a=test(list_1)
b=test
print(list_1)
print(b,a)
res=b(list_1)
print('this is b '+res) [, , , , ]
<function test at 0x027017C8> b
this is b b

3、函数返回值
 def test2(x):
x.append()
lz=[,,,]
lz=test2(lz)
print(lz) None

在函数没有返回值的时候默认是None。
4、python 中的为False:0、False、[]、{}、()、''、""。空列表、空字典、空字符创、空元组都是False.
二:内置函数
1:callable()该函数检测对象是否可以被调用。不常用这个函数。
 def test2(x):
x.append()
res=callable(test2)
print(res)
TEST=
res_1=callable(TEST)
print(res_1) True
False

2:chr()、odr()
字母在ASCII数字表示范围,大写字母在(65-90)小写字母在(97-122)

chr()是把数字转换成对应的字母。
 a=chr()
print(a)
N

ord()是把对应的字母转成数字。
 b=ord('a')
print(b)

应用:
我们经常在网站登录时候或者购买商品提交的时候,会有验证码的填写。那用python 如何产生随机的验证码?
 import random
num=random.randint(,)
num_1=random.randint(,)
st_1=chr(num_1)
sj=[]
for i in range():
m=random.randint(0,7)############需要注意的是这个,这个保证产生的验证码是随机的。如果指定的位置为数字或者字母,那就不是随机验证码。
if m== or m==:
sj.append(num)
else:
sj.append(st_1)
print('%s%s%s%s%s%s%s'%(sj[],sj[],sj[],sj[],sj[],sj[],sj[])) SS6SSSS

3、python代码是如何执行呢?

模拟这个过程:
 s='print([1,2,3,])'
t=compile(s,'','exec')##s是指可读取字符串的文件或者变量.内置函数compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1),
exec(t)###其中‘’表示字符串(或用""),可以在引号内填写任意内容。'exec'表示执行以哪种方式执行,exec表示一系列python语句,eval表示的是表达式可以进行求值。single表示单一的语句。 [, , ]

eval():通常用在表达式上,他有返回值。返回值是该表达是的值。表达式为字符串、后者是python表达式或者经过函数compile()编译过的代码。
其中表示:The source may be a string representing a Python expression or a code object as returned by compile().
 t=eval('2+2')
print(t)
 t='2*2+3'
s=compile(t,'','eval')
h=eval(s)
print(h)
eval()可以直接接受字符串表达式。
exec(),也可以处理字符串,但是没有返回值。也可以接受经过函数compile()编译过的代码。
 t='print(2*2+3)'
print(exec(t)) None
以后再模板引用的时候会用到把字符串格式的代码编译执行。

上述就是html格式的转换成一个函数,并为该函数提供全局变量,然后执行该函数。
将字符串格式转换成代码格式,并执行。
dir()和help()函数,他两个都是查看函数或者类的帮助文档。只是help()查看内容更为详细。而dir只是列出有什么方法和函数。

help()
 dimovd(x,y)求商和余数。x是被除数,y是余数。返回值是商和余数的元组。常用于分页计算。
 t=divmod(,)
print(t)
(, )

 实例是类的具体对象,他继承了类的所有特性(函数方法等。)比如如下字符串'abc'继承str所有的方法和函数。
isinstance(object,class or type)就是判断一个对象是否一个类的的实例,返回值是True或者False.
 a='abc'
t=isinstance(a,str)
print(t)
True
和type()区别:instance() 和type() instance() 中后面是基类或者父类 返回的也是TRUE 而 type()  只是返回一个当前一个类。

filter(x,y)函数,把符合的条件可以迭代的元素 生成一个生成器,然后用相应的函数进行转换。一般做筛选使用。
 def test(x):
if x>:
return True
x=[,,,,,]
t=filter(test,x)
print(list(t)) [, ]
整个过程:
 
 def test(x):
if x>:
return False
else:
return True
x=[,,,,,]
t=filter(test,x)
print(list(t)) [, , ]

 lambda(),返回值是布尔值,可以用lambda和filter结合使用。
 x=
test=lambda a:a>
print(test(x)) False
可以用2者结合。
 x=[,,,,]
test=filter(lambda a:a>,x)
print(list(test))
[, ]

 map()函数是对批量的对象进行相同的操作。同样也可以和lambda结合使用。
 x=[,,,,]
t=map(lambda a:a+,x)
print(list(t))
[, , , ]

len()函数计算字符长度。在不通的版本计算的方法不通,在python3中计算的是字符个数,如果在3中想计算字节的个数可以用bytes()函数转换成字节在用len()函数计算,是把字符转换成字节。在python2中计算字节的个数。

 print(len('生活'))
print(len(bytes('生活',encoding='gbk')))
print(len(bytes('生活',encoding='utf-8')))
max(),min(),sum函数。分别的是求最大值、最小值、求和。
 test_list=[,,,,]
print(max(test_list))
print(min(test_list))
print(sum(test_list))

hash()函数将字符或者其他对象求hash值。我们接触字典的key值就是hash值存储到磁盘。而且键值是可hash的。
 print(hash('a'))
 

pow()函数是求平方。等同于**
 a=pow(,)
print(a)
b=**
print(b)

 reversed()函数是反转的意思  但是并不操作原先的对象,而是生成新生成器对象,可以进行遍历的。
 test_list=[,,]
t=reversed(test_list)
print(t)
print(test_list)
for i in t:
print(i)
<list_reverseiterator object at 0x026701D0>
[, , ]

而字典的reserse()函数是直接操作原先的对象,进行反转。
 test_list=[,,]
test_list.reverse()
print(test_list)
[, , ]

 round()四舍五入。
 print(round(1.2))
print(round(1.5))

sorted() 排序从小打到。之前用过排序字典的key值,来保证有序输出
 test_list=[,,,,]
print(sorted(test_list))
[, , , ]

 zip()函数显示2个对象的都拥有的元素元组的列列表。
 list_1=[,,,]
list_2=[,,,]
list_3=[,,]
print(list(zip(list_1,list_2,list_3))) [(, , ), (, , )]

三:装饰器,功能在不修改类和函数的代码基础上加的额外功能。(函数可以做为实参赋值给形参。)
 USER_INFO={'evil':''}
AUTH_DIC={
'AUTH_FLAG':False
}
pre='''
:login
:change password'''
def test(func):
def prvi():
if AUTH_DIC['AUTH_FLAG']==False:
print('login first!')
else:
func()
return prvi def login(username,password):
if username=='evil'and password=='':
print('login successful!')
return True
else:
print('login fail')
@test
def chpass():
new_password=input('entre new password:')
USER_INFO['evil']=new_password
def login_main():
while True:
print(pre)
choice=input('entre your choice:')
if choice=='':
username=input('entre your login username:')
password=input('entre your login password:')
res=login(username,password)
if res:
AUTH_DIC['AUTH_FLAG']=True
continue
else:
AUTH_DIC['AUTH_FLAG']=False
continue
elif choice=='':
chpass()
print(USER_INFO)
login_main() :login
:change password
entre your choice:
login first! :login
:change password
entre your choice:
entre your login username:evil
entre your login password:
login successful! :login
:change password
entre your choice:
entre new password:

上面是简单的验证权限问题,在用户没登陆之前不能做修改密码的操作,在登陆之后可以进行修改密码的操作。
装饰器的语法:
 def outer(func):            ##定义装饰器函数outer并且参数为被装饰的函数整体。
def inner(): ##定义inner函数并做为outer函数的返回值,赋予func函数。
print('do before')
func()
print('do afer')
return True
return inner
@outer
def f1():
print(+) f1() do before do afer

语法:@函数名
1:自动执行outer()函数并且将下面的函数f1当做参数传递。
2:将outer函数的返回值,重新赋值给f1。
执行顺序:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAi8AAAE8CAIAAACHHMa7AAAgAElEQVR4nO2dW3Abdb7ne84sMEBgmBkmCeMQCLlAyI3YSex2HN9kSX2rhOd5gBeqXzacrbxC1civhKquPJwxMI+8QFF+OSF0bW2qqPXadWpP8ZLCp/DQZY1RbLxaHXu0ppFtyc70PrTU9261rv+W9P3Ur4ykvv2tUP3x7/f/dTclCIIgCDzPcxzHsmzi6oVXXnnlzJXxkZGRRJKLWLDhflaLhNdPspHk9BfxcOvHXWvGE+wLA4lD/WacvsoIgnD6KmN88sJAIl7ZthLJY+eS15wfMmfOJS45PhlMOra9Nhg/NmK+PjTIBL+OJ9j4RPLQa1MHXktcSrAjg/EDr8XPTLCuIbHxieShc8kR+4cjxuFGEgf6nYOJJ9hL/VPGeHoqpvx/Vo+45af7kzjJGB2LsWyCZRMclxB4xho8z3BskmHiPJcUeIbnkhyXYNkEzyd5PslzSY5NcEyc5xKCwAg8w3OcwPMcxzFcjOUZXuBYJsnEx5PMlMCxnMByHMMySYaZSnKTPJfkBYZjE2xiiklOcVxCEBieT7JsnGWTHJsU+KTAJQUuIfBJgU/w3FQ8EWeY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W6UOAABAJ9JKG7WxiwEAAEBH42Oj8hVFNkx7hOy4a0uHNwAAgC6g1XcGatXVrwAAALqJ1t+nrjV3BgIAANBNUIIgCILA8zzHcSzLJhKJWCw2Pj4+MjKSSHLWePyxfxL4qeDg2KClQ4PDg4NXx8fGLvfT166NJWLjF9+gJyfHLw1cHbo8zCQnLw8Mj09MCNzklcv95a24yYFR+vzVwaGJq1fGrl6dGtM/v3RtaGhiZHji2sAoPTA6PJUcPzM8OJkYvzw6PDA2HEuMnhkeiicn9KU8F9O3oi+/wVZeM1zs1UQsxsaSXGyKjU2xsRgbG2dj42xslI1dZWJXmdgwExusxOVk7DITu8LEhpjYCBMbY2PjbCzOxpJcjKvsM/rxxOO/jCdYRH0xFe5n+yJe7Wf1YKr9rCFicTb4Z00xOhaLxdkkwxGMRNLyk/H4WT2S4X4iklxbbXTt6rXJ2ESYkyaTGG/FudjYLcdNvTA1+cTk5FOTk8/GJn8Xmzw8NXlkKvZyPHYyETudiJ1PxPqTsUEmdpWJjbGxGBtLcFMcR14nsFHEhdRRKmqmkKqqqFYhEbdRVRU1TUiIemxUDY7jqq4TEXhBuMQw450z4KYAG7VURR0oJORGyI2iEr1ro94ENmq1kDpKRciNkBtFKP4/aIflX6sNfYYAAAAASUVORK5CYII=" alt="" />
python执行顺序是,从上到下,先将outer函数加载到内存,然后把函数f1加载到内存。在执行f1的时候,由于f1被outer装饰,f1作为实参赋值给outer函数的形参func,然后将outer函数的返回函数inner赋值给f1,
所以执行inner函数,因为到func()的调用时候,执行f1的旧函数的函数体,也就是7,执行完在执行第8步,如果f1有返回值,那么inner函数将返回相同的返回值。 如果函数有参数的时候,参数的对应是一一对应。
为了解决不同的被装饰的函数的参数个数问题,避免出现参数个数报错。可以用万能参数,来避免这个错误。
 def outer(func):
def inner(*args,**kwargs):
print('do before')
func(*args,**kwargs)
print('do afer')
return inner
@outer
def f1():
print(+)
@outer
def f2(x,y):
print(x*y) f1()
f2(,)
do before do afer
do before do afer

装饰器应用场景:大部分都是用来权限的验证。

												

python-内置函数、装饰器的更多相关文章

  1. Python 4 函数的参数,内置函数,装饰器,生成器,迭代器,

    一.函数的参数: 1.位置参数:调用函数时根据函数定义的参数位置来传递参数. 2.关键字参数:用于函数调用,通过“键-值”形式加以指定.可以让函数更加清晰.容易使用,同时也清除了参数的顺序需求. 3. ...

  2. Python—内置三大装饰器(@staticmethod、@classmethod、@property)

    https://blog.csdn.net/weixin_42681866/article/details/83376484 https://blog.csdn.net/weixin_43265804 ...

  3. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  4. python内置函数详细介绍

    知识内容: 1.python内置函数简介 2.python内置函数详细介绍 一.python内置函数简介 python中有很多内置函数,实现了一些基本功能,内置函数的官方介绍文档:    https: ...

  5. Python内置函数7

    Python内置函数7 1.propertypython内置的一个装饰器可参考https://blog.csdn.net/u013205877/article/details/77804137 2.q ...

  6. python 进阶篇 函数装饰器和类装饰器

    函数装饰器 简单装饰器 def my_decorator(func): def wrapper(): print('wrapper of decorator') func() return wrapp ...

  7. Python内置函数和内置常量

    Python内置函数 1.abs(x) 返回一个数的绝对值.实参可以是整数或浮点数.如果实参是一个复数,返回它的模. 2.all(iterable) 如果 iterable 的所有元素为真(或迭代器为 ...

  8. Python内置函数之-property

    property 是一个内置的装饰器函数,只在面向对象中使用 求一个圆的周长和面积 # 周长和面积都是通过类的方法得到from math import pi class Cricle: def __i ...

  9. Python | 内置函数(BIF)

    Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...

  10. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

随机推荐

  1. 151008:javascript不明白的地方

    http://www.cnblogs.com/ahthw/p/4841405.html,在这里面: function compare(num1, num2){ return num1 - num2; ...

  2. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序更新相关数据

    这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第八篇:为ASP.NET MVC应用程序 ...

  3. iOS - iOS 适配

    前言 什么是适配: 适应.兼容各种不同的情况. iOS 开发中,适配的常见种类: 1)系统适配, 针对不同版本的操作系统进行适配. 2)屏幕适配,针对不同大小的屏幕尺寸进行适配. iPhone 的尺寸 ...

  4. ERROR 1018 (HY000): Can't read dir of './test/' (errno: 13)

    不能查看mysql中数据库的表. 一.查看 mysql> desc test; ERROR 1046 (3D000): No database selected mysql> use te ...

  5. python 高级特性

    from http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 set set和dict ...

  6. UIApplication sharedApplication详细解释-IOS

    iPhone应用程序是由主函数main启动,它负责调用UIApplicationMain函数,该函数的形式如下所示: int UIApplicationMain ( int argc, char *a ...

  7. 使用jQuery Mobile的注意事项(译)

    翻译编辑自:http://www.appnovation.com/blog/7-things-know-about-jquery-mobile-working-it 一.Android和IOS的内置键 ...

  8. NOIP系列复习及题目集合

    首先是我的酱油记了啦~: Xs的NOIP2014酱油记,持续更新中 知识点方面: noip知识点总结之--贪心 noip知识点总结之--线性筛法及其拓展 noip知识点总结之--欧几里得算法和扩展欧几 ...

  9. PL/sql语法单元

    1.字符集 PL/SQL的字符集包括: 所有大小写字母:包括A~Z和a~z. 数字:包括0~9. 空白字符:包括制表符.空格和回车符 其他常用英文符号 2.标识符 标识符用于定义PL/sql变量.常量 ...

  10. iOS开发UI篇—从代码的逐步优化看MVC

    iOS开发UI篇—从代码的逐步优化看MVC 一.要求 要求完成下面一个小的应用程序. 二.一步步对代码进行优化 注意:在开发过程中,优化的过程是一步一步进行的.(如果一个人要吃五个包子才能吃饱,那么他 ...