一.类的定义 在Python中,一切皆对象,即便是类本身,也是一种type类型的特殊对象. class Person: def __init__(self, name, age): self.name = name self.age = age def sayHi(self): print ('Hello, my name is {}, my age is {}.'.format(self.name, self.age)) print(type(Person)) # 返回值为type 二.sel
1 collections系列 方法如下 class Counter(dict): '''Dict subclass for counting hashable items. Sometimes called a bag or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values. >>> c = Counter('abcdeabcdabcaba'
参考链接:老师 BLOG : http://www.cnblogs.com/wupeiqi/articles/4906230.html 入门拾遗 一.作用域 只要变量在内存中就能被调用!但是(函数的栈有点区别) 对于变量的作用域,执行声明并在内存中存在,如果变量在内存中存在就可以被调用. if 1==1: name = 'tianshuai' print name 所以下面的说法是不对的: 外层变量,可以被内层变量使用 内层变量,无法被外层变量使用 二.三元运算 result = 值1 if 条
1.list L = ['a','a','a','a','a','a3'] L[0] = a L[-1] = a3 添加新元素 L.append('paul') L.insert(-1,'Paul') 删除元素 L.pop(2) list 里面元素不要求必须是同一种数据类型 L.remove('Paul') 2.tuple (元组),tuple 一旦创建即不能修改: t = ('a',2,'awefawe',4) t[0] = a print t t = (1) 因为(
数值类型:整型(int)-通常被称为是整型或整数,是正或负整数,不带数点.长整型(long integers)-无限大小的整数,整数最后是一个大写或者小写的L浮点型(floadting point real values)-浮点型由整数部分与小数部分组成,也可以使用科学计数法表示复数(complex numbers)-复数的虚部以字母J或j结尾.如2+3i 1 int类型: 如:1, 78 , 99 class int(object): """ ) -> int or