num = 100
def func():
num = 123
print num
func()
num = 100
def func():
num += 100
print num
func()
num = 100
def func():
x = num + 100
print x
func()
def func():
x = num + 100
print x
func()
num = 100
def func():
num = 200
x = num + 100
prinx x
func()
num = 100
def func():
global num
num = 200
print num
func()
print num
num = 100
def func():
global num
num = 200
num += 100
print num
func()
print num
# calculator with all buttons import simplegui # intialize globals store = 0 operand = 0
# event handlers for calculator with a store and operand
def output():
"""prints contents of store and operand"""
print "Store = ", store
print "Operand = ", operand
print ""
def swap():
""" swap contents of store and operand"""
global store, operand
store, operand = operand, store
output()
def add():
""" add operand to store"""
global store
store = store + operand
output()
>>> if True: ... a = 'I am A' ... >>> a 'I am A'
g = 1 #全局的 def fun(): g = 2 #局部的 return g print fun() # 结果为2 print g # 结果为1
#file1.py var = 1 def fun(): print var var = 200 print fun() #file2.py var = 1 def fun(): var = var + 1 return var print fun()
a = 1
def external():
global a
a = 200
print a
b = 100
def internal():
# nonlocal b
print b
b = 200
return b
internal()
print b
print external()
from functools import wraps
def wrapper(log):
def external(F):
@wraps(F)
def internal(**kw):
if False:
log = 'modified'
print log
return internal
return external
@wrapper('first')
def abc():
pass
print abc()
def counter(start):
count =[start]
def internal():
count[0] += 1
return count[0]
return internal
count = counter(0)
for n in range(10):
print count()
# 1,2,3,4,5,6,7,8,9,10
count = counter(0)
print count()
# 1
def var(): pass def f2(): var = 'Just a String' f1 = globals()['var'] print var return type(f1) print f2() # Just a String # <type 'function'>
@app.route('/')
def view():
user = User.query.all()
article = Article.query.all()
ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
s = 'Just a String'
return render_template('index.html', user=user,
article = article, ip=ip, s=s)
#或者 return render_template('index.html', **locals())
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有