zoukankan      html  css  js  c++  java
  • The Python Tutorial 4. More Control Flow Tools的一些小记

      4.7.5. Lambda Forms

    By popular demand, a few features commonly found in functional programming languages like Lisp have been added to Python. With the lambda keyword, small anonymous functions can be created. Here’s a function that returns the sum of its two arguments: lambda a, b: a+b. Lambda forms can be used wherever function objects are required. They are syntactically restricted to a single expression. Semantically, they are just syntactic sugar for a normal function definition. Like nested function definitions, lambda forms can reference variables from the containing scope:

    关键字,用来创建小的匿名函数

    语法上限制单个表达式。其实和内嵌函数定义差不多

    >>> def make_incrementor(n):
    ...     return lambda x: x + n
    ...
    >>> f = make_incrementor(42)
    >>> f(0)
    42
    >>> f(1)
    43
    

    4.7.6. Documentation Strings

    其实就是对函数或者模块的说明

    Here is an example of a multi-line docstring:

    >>> def my_function(): ... """Do nothing, but document it. ... ... No, really, it doesn't do anything. ... """ ... pass ... >>> print my_function.__doc__ Do nothing, but document it. No, really, it doesn't do anything.
  • 相关阅读:
    vue.js初识(一)
    node.js安装
    array_unshift
    查看php 某个服务的进程数
    获取src 内容
    微信支付 composer 方法 --- 实测有效
    tp5.1 model 方法下的like语句查询
    tp5.1 where 时间查询
    nginx conf 文件
    怎么用Ubuntu系统制作Ubuntu系统盘
  • 原文地址:https://www.cnblogs.com/nickchan/p/3104528.html
Copyright © 2011-2022 走看看