[Head First Python]6. summary
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的更多相关文章
- [Head First Python]4. summary
1- strip()方法可以从字符串去除不想要的空白符 (role, line_spoken) = each_line.split(":", 1) line_spoken = li ...
- Python Syntax Summary
# _*_ coding: utf-8 _*_ """########################################################## ...
- [Head First Python]5. summary
1- "原地"排序-转换后替换 >>> list = [2,1,3] >>> list.sort() >>> list [1, ...
- Python初体验
今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...
- C#调用Python脚本打印pdf文件
介绍:通过pdf地址先将文件下载到本地,然后调用打印机打印,最后将下载的文件删除. 环境:windows系统.(windows64位) windows系统中安装python3.6.2环境 资料: O ...
- 05基于python玩转人工智能最火框架之TensorFlow基础知识
从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...
- Python实例--C#执行Python脚本,传参
# -*- coding: utf-8 -*- # 第一行的目的,是为了让代码里面,可以有中文注释信息. (否则要运行报错) # 这个 Python 脚本, 用于被 C# 来调用. # 简单测试 He ...
- Cheatsheet: 2013 09.22 ~ 09.30
Other Python basics summary Another article about big O notation Mobile Getting Started with PhoneGa ...
- TensorFlow应用实战 | TensorFlow基础知识
挺长的~超出估计值了~预计阅读时间20分钟. 从helloworld开始 mkdir 1.helloworld cd 1.helloworldvim helloworld.py 代码: # -*- c ...
随机推荐
- NAS4Free 安装配置(五)配置SMB
配置SMB 现在我们有2块存储设备,一块做下载盘,一块做数据盘 为了便于管理和扩展,我们分别在两块盘上建文件夹和Dataset 对于download盘,因为是UFS,所以只能建文件夹 我们把整个盘共享 ...
- python文件_写入
1.输入的数据写入到一个文本: #这个写入操作不会将原来的数据覆盖掉 n=raw_input('请输入写入的文件数据:') fl2=open('g:/2.txt','a') fl2.write('\n ...
- jquery之下拉列表select
选择下拉列表中的一项,文本框显示其值 html代码如下: <select id="ttt"> <option value="Volvo" id ...
- C++的ABI真特么是evil
果然有些公司明确禁止使用STL也是有一定道理的.其实这个问题的本质就是认为大部分开发者是蠢货,没水平掌控这些细节,项目Release万一出乱子了怎么办?为此吐个槽,我链接一个库时,由于编译参数和链接参 ...
- 图解SSL/TLS协议(转)
本周,CloudFlare宣布,开始提供Keyless服务,即你把网站放到它们的CDN上,不用提供自己的私钥,也能使用SSL加密链接. 我看了CloudFlare的说明(这里和这里),突然意识到这是绝 ...
- java.lang.OutOfMemoryError: unable to create new native thread(转)
解决 - java.lang.OutOfMemoryError: unable to create new native thread 工作中碰到过这个问题好几次了,觉得有必要总结一下,所以有了这篇文 ...
- Weekend counter
Weekend counter Sofia has given you a schedule and two dates and told you she needs help planning he ...
- 【HDU1875】畅通工程再续(MST基础题)
更改成实形数即可.第一次敲完直接交,CE了一次.晕. #include <iostream> #include <cstring> #include <cstdio> ...
- 决策树之ID3算法实现(python)
决策树的概念其实不难理解,下面一张图是某女生相亲时用到的决策树: 基本上可以理解为:一堆数据,附带若干属性,每一条记录最后都有一个分类(见或者不见),然后根据每种属性可以进行划分(比如年龄是>3 ...
- ora-28056 (Writing audit records to Windows Event Log failed)
系统:windows xp oracle 版本 SQL> select * from v$version; BANNER ------------------------------------ ...