2017.12.21-函数

# help(len)
# print(len) #<built-in function len>

# def print_tag():
# print('*'*10)
#
# def print_word():
# print('wangxin')
#
# print_tag()
# print_word()
# print_tag()


# def auth(name,password):
# # name= input('uaername:')
# # password = input('password:')
# if name == 'wang' and password == '123':
# print('success')
# else:
# print('error')
#
# a=auth('wang','123')
# print(a)


# def auth():
# name= input('uaername:')
# password = input('password:')
# if name == 'wang' and password == '123':
# print('success')
# else:
# print('error')
# #
# auth() #调用函数
# print(auth()) #打印返回值
# print(auth) #打印auth内存地址


# x=123
# def auth():
# print(x)
# name= input('uaername:')
# password = input('password:')
# if name == 'wang' and password == '123':
# print('success')
# else:
# print('error')
#
# auth()

# def bar():
# print('from bar')
# return 100
# def foo():
# print('from foo')
# bar()
#
# foo()

# def foo():
# print('from foo')
# bar()
# def bar():
# print('from bar')
# return 100
#
# foo()


# def foo():
# print('from foo')
# bar()
#
# foo() #NameError: name 'bar' is not defined
# def bar():
# print('from bar')
# return 100



# def my_max(): #函数写死了,error
# x=1
# y=2
# if x>=y :
# print(x)
# else:
# print(y)
#
# my_max()


# def my_max(x,y):
# if x>=y :
# print(x)
# else:
# print(y)
#
# my_max(1,2)

# def my_auth(name,password):
# if name == 'wang' and password == '123':
# print('success')
# else:
# print('error')
# def my_input():
# name= input('uaername:')
# password = input('password:')
# my_auth(name,password)
#
# my_input()

# def my_define():
# '''
#
# :return:
# '''

# def my_sum(a,b):
# # c=a+b
# return a+b
#
# my_sum(1,2)
# print(my_sum(1,2)) #3
# d=my_sum(1,2)
# print(d) #3
#
# def my_max(x,y):
# if x>=y :
# return x
# else:
# return y
# return 1111
#
# res=my_max(1,2)
# print(res)

# def bar():
# print('from bar')
# def foo():
# return bar

# print(foo()) #<function bar at 0x005AD738>
# foo() #<function bar at 0x01CBD738>


# def bar():
# print('from bar')
# return 100
# def foo():
# bar()
# return 200
#
# # foo() #from bar
# print(foo()) #from bar 200


# print(len('123'))

#默认形参的值,只在函数定义阶段被赋值一次
# res = 111
# res = 110
# def foo(x,y=res):
# print(x,y)
#
# res = 222
# foo(333) # 333 110

#
# def foo(a,b,*args):
# print(a,b,args)
#
# foo(1,2,3,4) #1 2 (3, 4)
#
#
# def foo(a,b,**kwargs):
# print(a,b,kwargs)
#
# foo(1,2,x=1,y='wang') # 1 2 {'x': 1, 'y': 'wang'}
#
#
# def foo(a,b,*args,**kwargs):
# print(a,b,args,kwargs)
#
# foo(1,2,11,222,333,x=1,y='wang') #1 2 (11, 222, 333) {'x': 1, 'y': 'wang'}
#
# def my_main(*args,**kwargs):
# print(args,kwargs)
#
# my_main(['b',222],'a',5,x=111,y='wang') #((['b', 222], 'a', 5) {'x': 111, 'y': 'wang'}

# def bar(x,y,z,**kwargs):
# print(x,y,z,kwargs)
# pass
# def my_main(*args,**kwargs):
# bar(*args,**kwargs)
#
# my_main(['b',222],'a',5,m=111,n='wang') #['b', 222] a 5 {'m': 111, 'n': 'wang'}


# def bar(x,y,z):
# print(x,y,z)
# pass
# def my_main(*args,**kwargs): #args=(1) kwargs={'z'=2,'y'=3}
# bar(*args,**kwargs) #bar=(*(1),**{'z'=2,'y'=3}) bar=(1,z=2,y=3)
#
# my_main(1,z=2,y=3)



#闭包函数:
#1 定义在函数内部的函数
#2 该函数的函数体代码包含对外部作用域(而不是全局作用域)名字的引用
#3 通常将闭包函数用return返回,然后可以在任意使用
# z=1
# def outer():
# x=1
# y=2
# def inner():
# print(x,y)
# # print(z)
# return inner
#
# f=outer()
# print(f.__closure__[0].cell_contents)
# print(f.__closure__[1].cell_contents)
# print(f.__closure__)


# def bar():
# x=111121
# y=2222
# f()
#
# bar()




# def foo(x,y):
# print(x+y)
#
# foo(1,2)

# def outter():
# x=1
# y=2
# def foo():
# print(x+y)
# return foo
#
#
# f=outter()
#
# f()



#爬页面
# import requests #pip3 install requests

# def get(url):
# response=requests.get(url)
# if response.status_code == 200:
# print(len(response.text))
#
# get('https://www.baidu.com')
# get('https://www.baidu.com')
# get('https://www.baidu.com')
#
# def outter(url):
# # url = 'https://www.baidu.com'
# def get():
# response=requests.get(url)
# # if response.status_code == 200:
# print(len(response.text))
# return get
#
# baidu=outter('https://www.baidu.com')
# python=outter('https://www.python.org')
# baidu()
# baidu()
# baidu()

# x=2
# def outer():
# # x=1
# def inner():
# print(x)
# print('hello')
# return inner
# x=3
# a=outer() #a=inner
# x=4
#
# def foo():
# x=4
# a()
#
# foo()

# y=11
# def outer():
# x=1
# def inner():
# print(x)
# print(y)
# # print(inner)
# return inner
#
#
# f=outer()
# # print(f)
# # f()
# print(f.__closure__)

import requests

# def get():
# response = requests.get('https://www.baidu.com')
# if response.status_code == 200:
# print(len(response.text))
#
# get()

# def get(url):
# response = requests.get(url)
# if response.status_code == 200:
# print(len(response.text))
#
# get('https://www.baidu.com')

# def outer():
# url='http://www.baidu.com'
# def get():
# response = requests.get(url)
# if response.status_code == 200:
# print(len(response.text))
# return get
#
# f=outer()
# f()



# def foo():
# x=1
# print(x)
# foo()
#
# def foo(x):
# print(x)
# foo(1)
#
# def outer(url):
# # url='http://www.baidu.com'
# def get():
# response = requests.get(url)
# if response.status_code == 200:
# print(len(response.text))
# return get
#
# baidu=outer('https://www.baidu.com')
# baidu()





















posted on 2017-12-21 14:46  泽禹W  阅读(138)  评论(0编辑  收藏  举报

导航