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. 使用 hibernate 根据映射文件生成数据库表

    为了更好的显示效果,可以在hibernate.cfg.xml配置文件的<session-factory>标签里加入以下内容: 显示sql语句和格式化显示sql语句: <propert ...

  2. Eclipse开启Mybatis-config.xml配置文件智能提示

    使用Java开发的程序员一般在学习的时候,可能都会涉及到使用配置文件,在使用Eclipse类似IDE进行编辑配置配置文件的时候,如果配置文件不能自动联想,是一件比较恼人的事情.笔者这里拿mybatis ...

  3. Android输入法 监听事件

    登录界面有一个输入用户名和密码的编辑框: private EditText et_userName;// 账户 private EditText et_password;// 密码 布局文件如下: & ...

  4. Python:staticmethod vs classmethod

    Being educated under Java background, static method and class method are the same thing. But not so ...

  5. 【git】error: Your local changes to the following files

    今天在服务器上git pull是出现以下错误: error: Your local changes to the following files would be overwritten by mer ...

  6. WPF Bug清单之(13)——应该出现却没有出现的ListView水平滚动条

    转载地址:http://www.cnblogs.com/nankezhishi/archive/2010/03/17/wpfbug13.html 我们知道ListView在内容超出控件本身范围时,默认 ...

  7. 解决:“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i38...

    编译android源码,找不到g++.通过apt-get下载时候,总是提示“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)” 的盘片插入 ...

  8. ApiDemos示例学习(2)——App->Activity->Animation

    现在介绍一下com.example.android.app包下的Animation示例. 关键类及函数: ActivityOption overridePendingTransition() make ...

  9. Mysql 关键字-保留字(转帖)

    2008-02-01 10:51 ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH ...

  10. 用代码场景Spine人物

    在使用Spine动画的时候可能会需要用代码创建,所以就小小的研究了一下 /// <summary> /// 加载一个spine的骨骼动画 /// </summary> /// ...