局部命名空间一般之间是独立,局部命名空间是调用函数时生成的
函数的名字指向它所在的地址
局部不会对全局产生影响,除非加global。
# def max(a,b):
# return a if a>b else b
#
# def the_max(x,y,z): #函数的嵌套调用
# c = max(x,y)
# return max(c,z)
#
# print(the_max(1,2,3)) #函数的嵌套定义
#内部函数可以使用外部函数的变量
# a = 1
# def outer():
# a = 1
# def inner():
# a = 2
# def inner2():
# nonlocal a #声明了一个上面第一层局部变量
# a += 1 #不可变数据类型的修改
# inner2()
# print('##a## : ', a)
# inner()
# print('**a** : ',a) # outer()
# print('全局 :',a) #nonlocal 只能用于局部变量 找上层中离当前函数最近一层的局部变量
#声明了nonlocal的内部函数的变量修改会影响到 离当前函数最近一层的局部变量
# 对全局无效
# 对局部 也只是对 最近的 一层 有影响
# a = 0
# def outer():
# # a = 1
# def inner():
# # a = 2
# def inner2():
# nonlocal a
# print(a)
# inner2()
# inner()
#
# # outer() # def func():
# print(123)
#
# # func() #函数名就是内存地址
# func2 = func #函数名可以赋值
# func2()
#
# l = [func,func2] #函数名可以作为容器类型的元素
# print(l)
# for i in l:
# i() def func():
print(123) def wahaha(f):
f()
return f #函数名可以作为函数的返回值 qqxing = wahaha(func) # 函数名可以作为函数的参数
qqxing()
#闭包:嵌套函数,内部函数调用外部函数的变量
# def outer():
# a = 1
# def inner():
# print(a)
# inner()
# outer() def outer():
a = 1
def inner():
print(a)
return inner
inn = outer()
inn() # import urllib #模块
from urllib.request import urlopen
# ret = urlopen('http://www.xiaohua100.cn/index.html').read()
# print(ret)
# def get_url():
# url = 'http://www.xiaohua100.cn/index.html'
# ret = urlopen(url).read()
# print(ret)
#
# get_url() def get_url():
url = 'http://www.xiaohua100.cn/index.html'
def get():
ret = urlopen(url).read()
print(ret)
return get get_func = get_url()
get_func()

python基础一 day9 函数升阶(3)的更多相关文章

  1. python基础一 day9 函数升阶(2)

    def max(a,b): return a if a>b else bprint(max(1, 2)) # 函数进阶# a = 1# def func():# print(a)# func() ...

  2. python基础一 day9 函数升阶(1)

    函数 可读性强 复用性强def 函数名(): 函数体 return 返回值所有的函数 只定义不调用就一定不执行 先定义后调用 函数名() #不接收返回值返回值 = 函数名() #接收返回值 返回值 没 ...

  3. python基础学习Day9 函数的初识,实参、形参、

    1.函数 def my_len(): l = [,,,,,,] count = for i in l: count += print(count) my_len() 定义的my_len()方法时,其结 ...

  4. python基础——内置函数

    python基础--内置函数  一.内置函数(python3.x) 内置参数详解官方文档: https://docs.python.org/3/library/functions.html?highl ...

  5. python学习第五讲,python基础语法之函数语法,与Import导入模块.

    目录 python学习第五讲,python基础语法之函数语法,与Import导入模块. 一丶函数简介 1.函数语法定义 2.函数的调用 3.函数的文档注释 4.函数的参数 5.函数的形参跟实参 6.函 ...

  6. 自学Python之路-Python基础+模块+面向对象+函数

    自学Python之路-Python基础+模块+面向对象+函数 自学Python之路[第一回]:初识Python    1.1 自学Python1.1-简介    1.2 自学Python1.2-环境的 ...

  7. python 基础 内置函数 和lambda表达式

    1.把任意数值转化为字符串有两种方法. (1)str()用于将数值转化为易于人读的形式.print(str("我是中国人"))>>>我是中国人 (2)repr() ...

  8. Python基础(协程函数、内置函数、递归、模块和包)-day05

    写在前面 上课第五天,打卡: 凭着爱,再回首: 一.协程函数(生成器:yield的表达式形式) 1.yield 的语句形式: yield 1 - 这种方式在 Python基础(函数部分)-day04  ...

  9. 『Python基础-13』函数 Function

    这篇笔记记录的知识点: 函数的基本概念 自定义函数 函数的几种参数 编程的三种方式: 1.OOP 面向对象编程,万物皆对象,以class为主,抽象化 2.POP 面向过程编程,万事皆过程,def定义过 ...

随机推荐

  1. MR 图像分割 相关论文摘要整理

    <多分辨率水平集算法的乳腺MR图像分割> 针对乳腺 MR 图像信息量大.灰度不均匀.边界模糊.难分割的特点, 提出一种多分辨率水平集乳腺 MR图像分割算法. 算法的核心是首先利用小波多尺度 ...

  2. FZU 2150 Fire Game (高姿势bfs--两个起点)(路径不重叠:一个队列同时跑)

    Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...

  3. Jquery等待ajax执行完毕继续执行(断点调试正常,运行异常)

    以前写过一个程序,发现用断点调试的时候,一步步的运行,程序是可以的,但是去了断点程序就出现了问题. $(document).ready(function(){ var arra=new Array() ...

  4. 454. 4Sum II

    Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such t ...

  5. 51nod1010【二分】

    打表+二分 #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL inf=1e18+10 ...

  6. [Xcode 实际操作]一、博主领进门-(3)使用资源文件夹(Assets.xcassets)导入并管理图片素材

    目录:[Swift]Xcode实际操作 本文将演示如何使用资源文件夹(Assets.xcassets)导入并管理图片素材. [Assets.xcassets]资源文件夹可以方便的进行图片的管理, 在读 ...

  7. Integrative Analysis of MicroRNAome, Transcriptome, and Proteome during the Limb Regeneration of Cynops orientalis (文献分享一组-翁海玉)

    文献名:Integrative Analysis of MicroRNAome, Transcriptome, and Proteome during the Limb Regeneration of ...

  8. 企业级应用,如何实现服务化五(dubbo综合案例)

    这是企业级应用,如何实现服务化第五篇.在上一篇企业级应用,如何实现服务化四(基础环境准备)中.已经准备好了zookeeper注册中心,和dubbo管理控制台.这一篇通过一个综合案例,看一看在企业级应用 ...

  9. [題解]luogu_P1854 花店櫥窗佈置

    來源:題解 一開始看不懂題目,一萬年了終於看懂 f [ i ] [ j ] 表示第i朵花放在第j個花瓶中最大美學值,(花是必須用完嗎?) 顯然放i-1朵花至少要放到前i-1個瓶子里,最多放到前j-1個 ...

  10. bzoj2818: Gcd懵逼乌斯反演

    由于是单组数据,强行不分块O(n)过 线性筛部分非常神奇,用了一个奇妙的推导(懒得写了) #include <bits/stdc++.h> using namespace std; ],f ...