Python快速教程Vamei博客 笔记(未完)
来源:互联网 发布:卖家怎么加入淘宝联盟 编辑:程序博客网 时间:2024/05/16 00:57
最近看基础,找一个不错的博客
博客地址:http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html
以下是我自己的一些记录和笔记
序列:
list 和 tuple 都是有序的,区别是list可变,tuple不可变
a=['a','b','c','d']print(a[1])print(a[:2])print(a[:-1])print(a[-1:])print(a[::-1])关于[::-1]曾经面试吃亏过,问我逆向一个字符串,当时懵逼,自己写了一个函数实现,问我还有简单的方法吗,我说不知道
结果:
b
['a', 'b']
['a', 'b', 'c']
['d']
['d', 'c', 'b', 'a']
循环:
continue
break
函数:
a=1def xx(a): a=a+1 return aprint(xx(a))print(a)
结果:
2
1
函数参数传递基础类型是值传递,内存中复制一份再传给函数
函数参数传递基础类型是值传递,内存中复制一份再传给函数
a=[1,2,3,4,5]def xx(a): a[0]=a[0]+1 return aprint(xx(a))print(a)
结果:
[2, 2, 3, 4, 5]
[2, 2, 3, 4, 5]
函数参数是列表之类是引用传递
面向对象基础概念:
定义一个带属性的类
#定义一个类class Bird(object): have_feather = True way_of_reproduction = "egg"#实例化类summer = Bird()print(summer.way_of_reproduction)
结果;
egg
定义一个带函数的类
#定义一个类class Bird(object): #类属性 have_feather = True way_of_reproduction = "egg" #类函数 def move(self, dx, dy): position = [0,0] position[0] = position[0] + dx position[1] = position[1] + dy return position#实例化类summer = Bird()print(summer.move(5,8))
结果:
[5, 8]
继承
#定义一个类class Bird(object): #类属性 have_feather = True way_of_reproduction = "egg" #类函数 def move(self, dx, dy): position = [0,0] position[0] = position[0] + dx position[1] = position[1] + dy return position#类的继承class Chicken(Bird): #定义自身类的属性 way_of_move = "walk" possible_in_KFC = Trueclass Oriole(Bird): way_in_move = "fly" possible_in_KFC = False#实例化类summer = Chicken()#调用自身类的属性print(summer.way_of_move)#调用父类的函数print(summer.move(5,8))
结果:
walk
[5, 8]
python类可以单继承也可以多继承,这并不矛盾,小明即是人又是学生还是男人,很合理
有些java程序员经常用伦理说明继承问题,一个人只有一个爹吧,多继承是一个人有多个爹,这就不合适吧
单继承 和 多继承 到底哪个合理,反正我没有到这么高的境界来讨论这个问题
类内部函数调用类属性和类方法
#创建一个类class Human(object): #类属性 laugh = "hahahaha" #类函数 def show_laugh(self): #类函数调用类属性 print(self.laugh) def laugh_100th(self): for i in range(5): #调用类函数 self.show_laugh()#实例化li_lei = Human()li_lei.laugh_100th()
结果:
hahahaha
hahahaha
hahahaha
hahahaha
hahahaha
__init__()函数
#定义一个类class Bird(object): #类属性 have_feather = True way_of_reproduction = "egg" #类函数 def move(self, dx, dy): position = [0,0] position[0] = position[0] + dx position[1] = position[1] + dy return position#类的继承class HappyBird(Bird): #初始化函数,类似java构造函数 def __init__(self, more_word): print(more_word)#实例化summer = HappyBird("happy,happy!")
结果:
happy,happy!
对象的性质
#创建类class Human(object): #初始化 def __init__(self, input_gender): self.gender = input_gender def printGender(self): print(self.gender)#实例化li_lei = Human("male")print(li_lei.gender)li_lei.printGender()
结果:
male
male
我对于对象性质的理解是对象实例化后才会产生的属性
#创建类class Human(object): #初始化 def __init__(self, input_gender): self.gender = input_gender def printGender(self): print(self.gender)#继承class Huuman(Human): def __init__(self, input_gender): self.gender = input_gender #子类的函数与父类相同,子类实例化后调用的是子类自己的函数 def printGender(self): print(self.gender+"! hahahah")#实例化li_lei = Huuman("male")li_lei.printGender()
结果:
male
male! hahahah
0 0
- Python快速教程Vamei博客 笔记(未完)
- java快速教程系列(转载于博客园--作者:vamei)
- Python快速教程 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起
- java快速教程-http://www.cnblogs.com/vamei/archive/2013/03/31/2991531.html
- Python学习笔记(未完)
- Python学习笔记(未完)
- Java教程--写的很好--有链接大家链接到博客园vamei的空间看吧
- python学习笔记(未完):线程
- 【Python教程】Python快速教程
- 《python网络编程基础》笔记(未完待续)
- python小笔记(未完待续)
- Python音频处理学习笔记(未完)
- Python快速教程
- Python快速教程
- Python快速教程
- Python快速教程
- Python快速教程
- Python快速教程总结
- 技术-技术方案优化策略--多线程与分布式
- BIM工程代码分析
- TensorFlow学习笔记(4)--实现多层感知机(MNIST数据集)
- 配置Nginx多核CPU,worker_cpu_affinity使用方法和范例
- Hadoop系列之FieldSelectionMapReduce用法
- Python快速教程Vamei博客 笔记(未完)
- 使用Subline开发React-Native编辑器环境搭建
- 数据结构1——稀疏多项式乘法计算器
- 资源管理模式:pooling模式
- Google C++编程风格整理(二)
- 技能概括
- [BZOJ 1002][FJOI2007]轮状病毒(高精+矩阵树定理?)
- 如何用R实现多元线性回归分析
- netbeans简单修改java程序左上角图标