Python基础零碎知识小笔记《2017-10-07》(个人向)
2017-10-07 22:29
686 查看
一、time的一些格式
time.strftime(“%Y-%m-%d %H:%M:%S”,data)
输出:’2017-10-07 21:11:04’
二、shelve模块
三、正则表达式
一个不错的博主总结,博主id为:WangSai.coo
http://blog.csdn.net/vip_wangsai/article/details/52090301
这位博主的总结也不错,
http://www.cnblogs.com/zj-luxj/p/6901048.html
四、with…open
五、参数代表意义
六、lambda函数
七、高阶函数
a :把一个函数名当做实参传给另一个函数(不修改被装饰函数,为其增加功能)
b : 返回值中包含函数名(不修改函数的调用方式)
八、函数的嵌套
九、装饰器
小提醒:参数为funcName(*args,**kwargs)
<
4000
p>参考本地deco.py文件
十、属性方法
//输出:the animal’s name is cat
//property的作用:将方法变为一个静态变量
//静态方法标记为@staticmethod
十一、数组增删改查
十二、元祖tuple
不能修改元祖中的元素。
十三、收集参数
十四、全局变量
在局部函数里面用global修饰变量即可修改全局变量的值
十五、三元运算符
十六、切片小知识
十七、字典
特性:
dict是无序的
key必须是唯一的,天生去重
十八、for表达式
help(time.strftime) Help on built-in function strftime in module time: strftime(...) strftime(format[, tuple]) -> string Convert a time tuple to a string according to a format specification. See the library reference manual for formatting codes. When the time tuple is not present, current time as returned by localtime() is used. Commonly used format codes: %Y Year with century as a decimal number. %m Month as a decimal number [01,12]. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %M Minute as a decimal number [00,59]. %S Second as a decimal number [00,61]. %z Time zone offset from UTC. %a Locale's abbreviated weekday name. %A Locale's full weekday name. %b Locale's abbreviated month name. %B Locale's full month name. %c Locale's appropriate date and time representation. %I Hour (12-hour clock) as a decimal number [01,12]. %p Locale's equivalent of either AM or PM. Other codes may be available on your platform. See documentation for the C library strftime function.
time.strftime(“%Y-%m-%d %H:%M:%S”,data)
输出:’2017-10-07 21:11:04’
二、shelve模块
d = shelve.open(xxx)
三、正则表达式
一个不错的博主总结,博主id为:WangSai.coo
http://blog.csdn.net/vip_wangsai/article/details/52090301
这位博主的总结也不错,
http://www.cnblogs.com/zj-luxj/p/6901048.html
re.search('(?P<id>[0-9]+)','abcd1234') //实质上{‘id’:‘1234’}
四、with…open
with open('xxx','w/r...') as f: pass with open('xxx','w/r...') as f1,open('xxx','w/r...') as f2: pass
五、参数代表意义
*args : 接收N个位置参数,转成元祖形式 **kwargs : 接收N个关键字参数,转成字典形式
六、lambda函数
calc = lambda x : x*9 print(calc(3)) //输出27
七、高阶函数
a :把一个函数名当做实参传给另一个函数(不修改被装饰函数,为其增加功能)
b : 返回值中包含函数名(不修改函数的调用方式)
类比数学中的函数
def dd(): print("dd") def ee(func): func() ee(dd) //输出dd
八、函数的嵌套
def test1(): def test2(): print("test2") test2() test1() //输出test2
九、装饰器
小提醒:参数为funcName(*args,**kwargs)
<
4000
p>参考本地deco.py文件
def deco(func): def fp(*args,**kwargs): print("Parameters are : ", *args,**kwargs) res = func(*args,**kwargs) return res return fp @deco # test1 = deco() def test1(*args,**kwargs): print("just test1!") @deco def test2(): print("just test2!") def index(): print("Welcome to index page!") index() test1('rr','tt','yy',{'da':'dad'}) test2() 输出结果为: Welcome to index page! Parameters are : rr tt yy {'da': 'dad'} just test1! Parameters are : just test2!
十、属性方法
class Animal(object): def __init__(self,name): self.__name = name @property def animal(self): print("the animal's name is %s"%(self.__name)) @animal.setter def animal(self,name): self.__name = name
an = Animal("cat") an.animal
//输出:the animal’s name is cat
//property的作用:将方法变为一个静态变量
//静态方法标记为@staticmethod
十一、数组增删改查
1、arrays.append(obj) 2、arrays.extend([obj,...]) 3、arrays.insert(num,obj) 4、arrays.remove(obj) 5、del arrays[num] 6、arrays.pop() 7、arrays[start:end] arrays[:end] arrays[start:] //分片
十二、元祖tuple
不能修改元祖中的元素。
temp = (1,) temp = 1, //有逗号就行,空元祖为()
十三、收集参数
def test(*params): //*params为收集参数 //test(1,2,3,4,5) //params[1]=2
十四、全局变量
在局部函数里面用global修饰变量即可修改全局变量的值
count=10 def test(): global count count = 5 //此时count=5
十五、三元运算符
a = result if b else c result : (b = true) ; result = c
十六、切片小知识
temp = [1,2,3,4,5,6] temp[-1] = 6 //逆着来,下标以1为基准 temp[1] = 2 //顺着来,下标以0为基准
十七、字典
特性:
dict是无序的
key必须是唯一的,天生去重
十八、for表达式
相关文章推荐
- python基础知识-个人笔记
- Python学习笔记——基础知识
- 【学习总结】Python基础知识笔记2
- Python学习第一天——基础知识(笔记)
- Python学习笔记(基础知识点二)开更了~
- Python学习笔记一 基础知识
- Python学习的个人笔记(基础语法)
- Python学习笔记-第一章 基础知识
- python学习笔记-Day13 -css基础知识
- Python笔记-容易出错应牢记的基础知识
- python3学习笔记:1.基础知识
- python笔记(基础知识)
- python个人笔记(一)基础语法
- 【python学习笔记一】程序设计计算机基础知识
- [Python笔记]第一篇:基础知识
- python学习笔记1:基础知识
- Python学习入门笔记-基础知识
- Git基础知识1——个人笔记
- 第1章 Python笔记 基础知识
- Python学习笔记:程序设计的基础知识