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. overflow应用随记

    今天在帮别人改页面时遇到了overflow属性,虽然对他已经比较熟悉了,但还是去专门查找了一下.和大家分享下. overflow 属性规定当内容溢出元素框时发生的事情. 这个属性定义溢出元素内容区的内 ...

  2. ffmpeg编译时freetype2 not found错误

    自己安装的libfreetype2在/usr/local/lib目录下export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

  3. 安装Oracle10g on RedHat as 4 64bit(摘)

    一.安装前的配置 1.修改RH版本 vi /etc/redhat-release Red Hat Enterprise Linux AS release 3 (Taroon Update 3) 2. ...

  4. android获取sdk更新

    http://www.th7.cn/Program/Android/201310/154981.shtml 网上许多解决 Android SDK Manager 无法更新(下载)的问题的方法基本都是将 ...

  5. LeetCode_Populating Next Right Pointers in Each Node

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  6. java.lang.OutOfMemoryError: GC overhead limit exceeded 问题分析和解决(转)

    在项目历史数据导入过程中,出现了应用无法访问的情况.立刻对Weblogic进行分析,发现Weblogic的内存.线程等性能良好,Server也是Running的状态.随后查看了Weblogic日志,在 ...

  7. shell操作mysql

    参考: http://blog.csdn.net/hbcui1984/article/details/5125387

  8. Linux 下通过脚本实现远程自动备份

    考虑到在本机上备份数据,一旦该机器硬盘出现故障,数据无法取出.远程手动备份数据费时费力且不及时.最好的方法就是通过脚本实现远程自动互备.但远程无论是通过SSH登陆,还是通过scp拷贝文件都需要输入密码 ...

  9. C#优秀开源资料收集

    1. 把对命令行程序的调用封装起来,通过程序里进行输入,调用命令行程序的输出显示在程序中 http://www.codeproject.com/Articles/335909/Embedding-a- ...

  10. Uva11183-Teen Girl Squad(有向图最小生成树朱刘算法)

    解析: 裸的有向图最小生成树 代码 #include<cstdio> #include<cstring> #include<string> #include< ...