zoukankan      html  css  js  c++  java
  • 小白学Python 之函数 二

    #定义一个函数
    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
  • 相关阅读:
    java面试题
    linux下的文件目录结构
    Linux的基础命令
    Linux系统的介绍
    逻辑思维题
    37-字符的全排列
    36-螺旋矩阵
    35-面试:如何找出字符串的字典序全排列的第N种
    34-数细线
    33-求极差
  • 原文地址:https://www.cnblogs.com/taisuyuanqing/p/6843086.html
Copyright © 2011-2022 走看看