list&tuple 运算

乘以constant

>>> x = ((1,2),)
>>> x*2
((1, 2), (1, 2))
>>> x = ((1,2))
>>> x*2
(1, 2, 1, 2)
>>>

从上面可以看出,tuple或者list和一个常数相乘,会复制元素得到一个新的tuple或list,需要注意的是有无逗号,这将决定是复制元素还是 "子tuple"。

tuple或list相加

>>> a = [1,2,3,4,5]
>>> a + [6]
[1, 2, 3, 4, 5, 6]
>>> a = (1,2,3,4,5)
>>> a +(6) Traceback (most recent call last):
File "<pyshell#189>", line 1, in <module>
a +(6)
TypeError: can only concatenate tuple (not "int") to tuple
>>> a + (6,)
(1, 2, 3, 4, 5, 6)
>>> type((6))
<type 'int'>
>>> type([6])
<type 'list'>
>>>

  tuple和list在此处略有区别

Class 类的处理

在Python中子类继承父类的过程中,如果子类不覆盖父类的__init__()方法,则子类默认将执行与父类一样的初始化方法。但是假如子类自己重写了(也成为覆盖)父类的__init__()方法,那么就需要显式的调用父类的初始化方法了。有两种方法可以做到:

1:ParentClass.__init__(),父类名加上init函数

2:super(type,cls).__init__()

重点介绍下这个,这个也是Python在借鉴了C++和JAVA的经验后,做出的改进语言熟悉程度的一种努力。

super(type,cls)实质上是super类的3个静态方法之一。

python Memo的更多相关文章

  1. Python Memo 赋值与ID (Assignment & id())

    利用Python内置函数id()找出内部地址,探讨赋值与内建地址. id()的官方解释:this is the address of the object in memory 那么 a =1 是什么意 ...

  2. <Think Python>中斐波那契使用memo实现的章节

    If you played with the fibonacci function from Section 6.7, you might have noticed thatthe bigger th ...

  3. Python Day19

    Django Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Sessio ...

  4. python中类的三种属性

    python中的类有三种属性:字段.方法.特性 字段又分为动态字段和静态字段 类 class Province: #静态字段 memo = 'listen' #动态字段 def __init__(se ...

  5. Python之路Day19-Django(二)

    本节内容概要: 一.路由系统URL 二.视图 三.模板 四.ORM操作 问题1:Django请求生命周期 -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串 -> ...

  6. python Django session/cookie

    一, Cookie #cookie # def cook1(request): # print(request.COOKIES) # 查看cooke # # print(request.get_sig ...

  7. python Django 进阶篇

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  8. Default Parameter Values in Python

    Python’s handling of default parameter values is one of a few things that tends to trip up most new ...

  9. Python自动化之django的ORM操作——Python源码

    """ The main QuerySet implementation. This provides the public API for the ORM. " ...

随机推荐

  1. Your build settings specify a provisioning profile with the UUID, no such provisioning profile was found的解决方案

    在Archive项目时,出现了“Your build settings specify a provisioning profile with the UUID “”, however, no suc ...

  2. CodeBlocks13.12汉化以及去掉注释及字符串的下划线

    汉化: 在安装目录 D:\Program Files\CodeBlocks\share\CodeBlocks(我的安装目录)下,新建文件夹locale,然后在locale文件夹内建立文件夹zh_CN ...

  3. golang sha1 signature

    package models import ( "crypto/hmac" "crypto/sha1" "encoding/base64" ...

  4. 初学swift笔记-数组、字典、元组(三)

    数组的使用.字典的使用.元组的使用 import Foundation //1.定义数组 //集合数据 数组.字典 ,,,]//常用定义 ,,,]//常用定义 ,,,]//范型定义 ,,,] arr_ ...

  5. 嵌入式平台组件白盒测试gcov、lcov和genhtml 使用指导

    在嵌入式平台上使用了gtest白盒测试工具,覆盖了被测函数,但是不知道自己测试的效果如何,测试行覆盖率.函数覆盖率,分支覆盖率的数据. 便开始研究gcov这个代码覆盖率工具能否使用,来检查白盒测试的效 ...

  6. Linux06--Shell程序设计02 数据流重定向与管道

    包含3种数据流: •标准输入(stdin):代码为0,符号为<或<<; •标准输出(stdout):代码为1,符号为>或>>; •标准错误输出(stderr):代码 ...

  7. [问题解决] /home目录占用率100%

    今天发现一个比较奇怪的现象,linux系统下一个目录挂在存储下,df -Th 显示该目录使用率100%, du 该目录显示只用了2%, 后来发现是由于进程占用了被删掉的文件空间导致.举例如下: [ro ...

  8. SP_CreateInsertScript 将表内的数据全部拼接成INSERT字符串输出

    ),)) as begin set nocount on ) ) ) select @sqlstr='select ''insert '+@tablename select @sqlstr1='' s ...

  9. uva10934 Dropping water balloons

    //好久没做题 一直没状态 然后刷了个水题玩玩 //寒假集训和校赛都做到了类似的题目 然而当时并不会 (其实现在也不会 题意:有k个气球和一个n层高的楼,气球有硬度,在某曾会恰好摔碎,问至少多少次实验 ...

  10. Colorbox cannot load the image added by js

    As we know, Colorbox is a wonderful js plugin. I came up against a head-banged problem in v1.5.6. Wh ...