zoukankan      html  css  js  c++  java
  • 《Django Web 开发指南》第一章 读书笔记

    1,列表推导式

     由逻辑代码组成的结构,构造了一个包含了由逻辑代码生成的值或对象的列表(集合的描述法)

    data = [x+1 for x in range(10)]

    2,生成器表达式

    把列表推导的方括号换成圆括号

    输入的序列变得很大时,考虑使用生成器表达式代替列表推导式

    3,列表用方括号声明,元组用圆括号声明,字典用花括号声明

    4,单个元素的元组要求元素后面必须跟一个逗号

    5,匿名函数

    lambda person: person.last_name

    等价于

    def get_last_name(person) :
        return person.last_name

    6,单星号用来打开列表和元组,双星号用来打开字典,详情看代码:)

    host_info = ('www.python.org', 80, '/')
    
    #以下两句效果相同
    
    check_web_server(host_info[0], host_info[1], host_info[2])
    
    check_web_server(*host_info)

    7,通过在函数签名中加入*,来使函数可以接收不定个数的参数,详情看代码

    def daily_total(*all_sales):
        ...
    #调用此函数
    daily_total(5.00, 1.50, '128.75')

    8,@符号为函数添加装饰器

    @deco
    def foo() :
        pass

    等效于:

    foo = deco(foo)

    9,可以用__del__方法实现类似于析构方法的效果

    10,可以用del语言结构来显式的销毁对象

    del my_object
  • 相关阅读:
    Redis源码分析(二十一)--- anet网络通信的封装
    leetcode 总结part1
    leetcode String to Integer (atoi)
    leetcode 165. Compare Version Numbers
    leetcode 189. Rotate Array
    leetcode 168. Excel Sheet Column Title
    leetcode 155. Min Stack
    leetcode 228. Summary Ranges
    leetcode 204. Count Primes
    leetcode 6. ZigZag Conversion
  • 原文地址:https://www.cnblogs.com/unsea/p/2605744.html
Copyright © 2011-2022 走看看