码迷,mamicode.com
首页 > 编程语言 > 详细

Python(56)_函数进阶

时间:2019-01-09 21:49:30      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:print   全局   input   UNC   .com   bow   变量   命名   http   

1  函数的命名空间

#-*-coding:utf-8-*-
‘‘‘
函数进阶
‘‘‘
‘‘‘
全局变量a,函数里面可以调用‘‘‘
a = 1
def fun():
    print(a)
fun()

‘‘‘
覆盖内置函数,调用时调用的是这个函数了,而不是python本身有的input()
‘‘‘
def input():
    print("in input function")
input()

‘‘‘
覆盖内置函数,用时调用的是这个函数了,而不是python本身有的max(),
‘‘‘
def  max():
    print(in max function)
max()
# max([1,2,3]) 这样是会报错的!

‘‘‘
这样也会调用全局的,一级一级往上调
‘‘‘
def aa():
    input()
aa()

 

2  函数调用的本质

#-*-coding:utf-8-*-
‘‘‘
函数进阶
‘‘‘
‘‘‘

‘‘‘
a = 1
def bowen():
    print(a)
print(id(bowen))
print(bowen)

技术分享图片

 

Python(56)_函数进阶

标签:print   全局   input   UNC   .com   bow   变量   命名   http   

原文地址:https://www.cnblogs.com/sunnybowen/p/10246756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!