1- 字典-内置数据结构,数据值与键值关联

键-字典中查找部分

值-字典中数据部分

使用dict()工厂函数或者只用{}可以创建一个空字典

>>> list = {}
>>> list['name']='hello'
>>> list['pwd']='world'
>>> list['name']
'hello'
>>> list['Occupation']=['','','']
>>> list['Occupation'][-1]
''
>>> list['Occupation'][-2]
''

2- 类 用def __init__()方法初始化对象实例

类中每个方法都必须提供self作为第一个参数

类中每个属性前面都必须有self,从而将数据与其实例关联

类可以从0创建,也可以从python内置类或其他定制类继承

类可以放置到模块中

从0创建

 class hi:
def __init__(self, a_name, a_dob=None, a_times=[]):
self.name = a_name
self.dob = a_dob
self.times = a_times sarah = hi('sarah', '2002-1-1', ['','','','-1'])
james = hi('james') print(type(sarah))
print(type(james)) print(sarah)
print(james) print(sarah.name + ' ' +str (sarah.dob) + ' ' +str(sarah.times))
print(james.name + ' ' +str (james.dob) + ' ' +str(james.times))

继承内置类

 class NameList(list):
def __init__(self,a_name):
list.__init__([])
self.name = a_name johnny = NameList("John Paul Jones")
print(type(johnny))
print(dir(johnny)) johnny.append("Bass Player")
johnny.extend(["a","b","c"])
print(johnny)
print(johnny.name)

[Head First Python]6. summary的更多相关文章

  1. [Head First Python]4. summary

    1- strip()方法可以从字符串去除不想要的空白符 (role, line_spoken) = each_line.split(":", 1) line_spoken = li ...

  2. Python Syntax Summary

    # _*_ coding: utf-8 _*_ """########################################################## ...

  3. [Head First Python]5. summary

    1- "原地"排序-转换后替换 >>> list = [2,1,3] >>> list.sort() >>> list [1, ...

  4. Python初体验

    今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...

  5. C#调用Python脚本打印pdf文件

     介绍:通过pdf地址先将文件下载到本地,然后调用打印机打印,最后将下载的文件删除. 环境:windows系统.(windows64位) windows系统中安装python3.6.2环境 资料: O ...

  6. 05基于python玩转人工智能最火框架之TensorFlow基础知识

    从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...

  7. Python实例--C#执行Python脚本,传参

    # -*- coding: utf-8 -*- # 第一行的目的,是为了让代码里面,可以有中文注释信息. (否则要运行报错) # 这个 Python 脚本, 用于被 C# 来调用. # 简单测试 He ...

  8. Cheatsheet: 2013 09.22 ~ 09.30

    Other Python basics summary Another article about big O notation Mobile Getting Started with PhoneGa ...

  9. TensorFlow应用实战 | TensorFlow基础知识

    挺长的~超出估计值了~预计阅读时间20分钟. 从helloworld开始 mkdir 1.helloworld cd 1.helloworldvim helloworld.py 代码: # -*- c ...

随机推荐

  1. hdu 2034

    Problem Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法 ...

  2. mysql在关闭时的几个阶段

    mysql关闭的大致过程 1.The shutdown process is initiated 初始化关机过程有许多种方法1.mysqladmin shutdown ; 2.kill pid_of_ ...

  3. nodejs应用mysql(纯属翻译)

    原文点击这里 目录 Install Introduction Contributors Sponsors Community Establishing connections Connection o ...

  4. mysql设置连接等待时间(wait_timeout)

    Linux下mysql修改连接超时   1,首先进入mysql,查看 wait_timeout.interactive_timeout这个值是否为默认的8小时(即 28800)  [root@serv ...

  5. 开心菜鸟学习系列-----javascript(2)

    最小全局变量 :        1)每个javascript环境有一个全局对象,当你在任意的函数外面使用this的时候可以访问到,你创建的每一个全部变量都成了这个全局对象的属性,在浏览器中,方便起见, ...

  6. keil c51 本變數型態(Variable Type)

    本變數型態(Variable Type): 類 別 符號位元 位元組(bytes) 表 示 法 數 值 範 圍 整 數 有 2 int(short) -32768~0~>32767 4 long ...

  7. Qt基于FFmpeg播放本地 H.264(H264)文件(灿哥哥的博客)

    最近在弄H264的硬件编解码,基于DM3730,但是为了调试方便,在小红帽上用FFmpeg实现了H264的软件编解码.现在弄了一个Windows的例子,给需要的同学参考一下,如果大家觉得有帮助,可以小 ...

  8. 时间类处理<1>

    2016/05/31 14:47:21 [emerg] 14629#0: location "/nginx_status" is outside location "/p ...

  9. Linux用户管理(笔记)

    用户:UID, /etc/passwd组:GID, /etc/group 影子口令:用户:/etc/shadow组:/etc/gshadow 用户类别:管理员:0普通用户: 1-65535    系统 ...

  10. PHP计算一个目录文件大小方法

    <?php $dirfile='../hnb'; /** *计算一个目录文件大小方法 *$dirfile:传入文件目录名 **/ function dirSize($dirfile) { $di ...