python Memo
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的更多相关文章
- Python Memo 赋值与ID (Assignment & id())
利用Python内置函数id()找出内部地址,探讨赋值与内建地址. id()的官方解释:this is the address of the object in memory 那么 a =1 是什么意 ...
- <Think Python>中斐波那契使用memo实现的章节
If you played with the fibonacci function from Section 6.7, you might have noticed thatthe bigger th ...
- Python Day19
Django Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Sessio ...
- python中类的三种属性
python中的类有三种属性:字段.方法.特性 字段又分为动态字段和静态字段 类 class Province: #静态字段 memo = 'listen' #动态字段 def __init__(se ...
- Python之路Day19-Django(二)
本节内容概要: 一.路由系统URL 二.视图 三.模板 四.ORM操作 问题1:Django请求生命周期 -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串 -> ...
- python Django session/cookie
一, Cookie #cookie # def cook1(request): # print(request.COOKIES) # 查看cooke # # print(request.get_sig ...
- python Django 进阶篇
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...
- 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 ...
- Python自动化之django的ORM操作——Python源码
""" The main QuerySet implementation. This provides the public API for the ORM. " ...
随机推荐
- 在Fedora 23 Server和Workstation上安装LAMP(Linux, Apache, MariaDB和PHP)
在安装LAMP之前,建议先更新系统包$ sudo dnf update 第一步:安装Apache Web服务器1.在Fedora 23安装Apache,你可以运行下面的命令:$ sudo dnf in ...
- div+css中常见的浏览器兼容性处理-兼容不同浏览器
在网站设计的时候,应该注意css样式兼容不同浏览器问题,特别是对完全使用DIV CSS设计的网,就应该更注意IE6 IE7 FF对CSS样式的兼容,不然,你的网乱可能出去不想出现的效果! div+cs ...
- zendStudio安装Xdebug项目断点调试
1,首先安装xdebug插件 传送门 2,配置php.ini文件如下: [XDebug] xdebug.profiler_append = xdebug.profiler_enable = xdebu ...
- yum mysql
linux下使用yum安装mysql 1.安装 查看有没有安装过: yum list installed mysql* rpm -qa | grep mys ...
- Google搜索的配置方法
在百度慢慢沦落为广告商的搜索引擎之后,对于一个追求技术的程序员,他所要追求的搜索引擎永远都应该是google. 下面保存一下我使用的能够FQ实现google搜索的方法和一些面试的测试账号. 小飞机sh ...
- Solaris-[ODBC-ORACLE WP Driver]遇到的几个问题
确保之前已装好ORACLE和ODBC,ODBC连接数据库时会出现几个问题 一.登陆oracle并启动 [root@bunsol:/export]$su - oracle Oracle Corporat ...
- Delphi 服务操作
unit Service; interface uses Windows,Messages,SysUtils,Winsvc,Dialogs; function StartServices(Const ...
- C#句柄使用
原文:C#句柄使用 调用 API 函数 SendMessage 发送 WM_CLOSE 消息. DllImport("User32.dll",EntryPoint="Se ...
- 在esx上 docker的网络桥接
docker:/root# docker run -itd --net=none --name zjtest8_haproxy 192.168.32.150:5000/zjzc_centos6.5_m ...
- poj3100---求根问题
题意:a的n方=b,a这个整数与b开n方的值相近,分别向上取整和向下取整,同时n方,b一定介于这两个整数之间,然后比较这两个数与b的距离,取最近的 收获:c++的cei和floor函数在c中的向上取整 ...
