zoukankan      html  css  js  c++  java
  • python学习(四)

    ubuntu用aptitude安装程序

    sudo aptitude install

    python数据分析学习图解

    sudo aptitude install ipython ipython-notebook -y
    ipython notebook --pylab=inline
    浏览器输入:http://127.0.0.1:8888

    在python中如果要改写全局变量,一定要用global声明。

    #coding:utf-8
    
    l1 = ['a', 'b']
    
    def my_list(a):
    #       global l1
            l1 = []
            l1.append(a)
    
    def my_add(a, b):
            return a+b+x
    
    my_list(1)
    my_list("3")
    
    print l1
    
    输出结果['a', 'b']
    如果不注释掉global l1,则结果为['3']

    python可以给函数指定参数传参

    #coding:utf-8
    
    def my_test(a,b):
            a = a*3
            return a + b
    
    print my_test(b=4, a=2)

    输出结果为10

    列表的遍历

    #coding:utf-8
    l1=[12,[3,[1,3,4,["fdsa",1]]]]
    
    
    def print_all(l):
            for n in l:
                    if isinstance(n,list) and len(n) > 0:
                            print_all(n)
                    else:
                            print n,
    
    
    print_all(l1)
  • 相关阅读:
    图的深度遍历
    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历

    满汉全席
    2-sat(模板)
    2-sat
    花匠
    维护序列NOI2005
    序列终结者
    杨辉三角
  • 原文地址:https://www.cnblogs.com/goodhacker/p/3163524.html
Copyright © 2011-2022 走看看