python函数局部变量如何改变外部变量,之前我说过,局部变量是没办法改变外部变量的,除非局部变量找不到,去外部找,输出变量,使用关键词global 使变量改变外部变量. 1,使用关键词global name='this is a girl' def chan_sex(): global name name=''this is a boy’ print(name) chan_sex() print(name) 输出结果 :this is a boy 输出结果:this is a boy 注意使用…
def make_pizza(size,*toppings): print("\nmaking a "+str(size)+" size pizza with following toppings:") for topping in toppings: print("-"+topping) make_pizza(12,'apple') make_pizza(25,"banana","mango","…
sandwiches_orders = ['apple','banana','mango',"apple","watermelon"] finished_sandwiches = [] while "apple" in sandwiches_orders: sandwiches_orders.remove("apple") print("sorry ,The apple is sold out!/nyour orde…