• Python 学习笔记


     

    >>> x = y = z = 0  # Zero x, y and z
    a, b = 0, 1

    >>> tax = 12.5 / 100
    >>> price = 100.50
    >>> price * tax
    12.5625
    >>> price + _
    113.0625


    >>> range(10)
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> range(5, 10)
    [5, 6, 7, 8, 9]
    >>> range(0, 10, 3)
    [0, 3, 6, 9]
    >>> range(-10, -100, -30)
    [-10, -40, -70]

    The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced.

    The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call.


    >>> fib
    <function fib at 10042ed0>
    >>> f = fib
    >>> f(100)
    0 1 1 2 3 5 8 13 21 34 55 89



     In fact, even functions without a returnstatement do return a value, albeit a rather boring one. This value is called None



    result = []

    result.append(a) equivalent to result = result + [a]


     in keyword. This tests whether or not a sequence contains a certain value.
    if ok in ('y', 'ye', 'yes'):
                return True


    def f(a, L=[]):
        L.append(a)
        return L
    
    print f(1)
    print f(2)
    print f(3)

    The default value is evaluated only once!!!!
    [1]
    [1, 2]
    [1, 2, 3]

    If you don’t want the default to be shared between subsequent calls, you can write the function like this instead:

    def f(a, L=None):
        if L is None:
            L = []
        L.append(a)
        return L

    a is required argument, L is optional argument


    >>> range(3, 6)             # normal call with separate arguments
    [3, 4, 5]
    >>> args = [3, 6]
    >>> range(*args)            # call with arguments unpacked from a list
    [3, 4, 5]


    
    
    for idx, val in enumerate(ints):

      print idx, val


     
     
     
  • 相关阅读:
    OpenCv 学习安装(一)
    mysql 5.7.22安装
    sql游标
    (转)C# 获取当前路径的7中方法
    IIS 配置好了,为什么网站打开一片空白?
    (转)C#文件操作
    关于电脑开机不出现桌面即不启动explorer.exe桌面程序--------正解
    C#中 非静态字段、方法或属性“XXXX”要求对象引用-----解决方案
    关于svn获取获取文件时 Unable to connect to a repository at URL"https://..."执行上下文错误:参数错误
    获取汉字全拼、首字母缩写
  • 原文地址:https://www.cnblogs.com/wintor12/p/3550512.html
Copyright © 2020-2023  润新知