#定义一个函数 def getname(name): print ("请叫我{}!".format(name)); return; def GetItem(k): b=0; for i in k: b=b+i; print (b); return b; #调用 getname("小王"); k=[1,2,34,5,3,56,45,6,56,767,98]; GetItem(k); def getfive(): return "3","as","test"; #接收参数 a,b,x=c=getfive(); print (a+"*"+b+"*"+x); #参数和作用域 def add_five(num): #num=num+7; num=num+"手机"; print (num); return num; k=9; m="小明"; add_five(k); add_five(m); print ("新一代{}".format(m)); def main(): print ("好好学习天天向上") if __name__ == '__main__': main();
字典
def main(): #字典 dic={"name":"wangds","age":18,"address":"beijing"}; print (dic["name"]); #添加字典数据 dic['phone']="苹果"; print (dic); #清理字典 dic.pop("name"); print (dic); dic={"name":"wangds","age":18,"address":"beijing"}; dic1={"name":"wangds","age":18,"address":"beijing"}; dic2={"name":"wangds","age":18,"Address":"beijing"}; #包含 # print ("name" in dic) #所有key print (dic.keys()) #所有values print (dic.values()) #对比字典 print (dic==dic1) print (dic==dic2) for k in dic: print (k)#循环key print (dic[k]);#循环values