-
编码指定:
# -*- coding: UTF-8 -*-
-
流程控制:
- 条件语句-if
if x < 0: pass elif x == 0: pass else: pass
- 循环语句-for
for i in range(5): pass
-
数据结构:
a = [22,33,44] //list a.insert(2,-1) a.append(55) a.index(22) a.remove(22) a.reverse() a.sort() a.pop() del a //删除列表 t = 1,2,3,'hello' //元组 u = t,(1,2,3) //元组 h = 'tt', //元组 m = set('aaaabbbccc') //set d = {'t1':222, 't2': 333} //dict //循环dict for k, v in d.items(): print(k,v) //循环列表 for i, v in enumerate(['a','v','c']): print(i, v) //zip 循环两个序列 按照顺序取值 q = ['name','age'] an = ['mn','22'] for q, a in zip(q, an): print(q, a)
-
main方法模板:
if __name__ == "__main__": pass
-
异常处理:
try: except: else: finally:
-
类模板:
class Sample: """类文档说明""" i = 123 //类属性 __private_name = 222 //私有变量 def __init__(self,name): self.name = name def f(self)://类方法 return 'hello'
-
Notifications
You must be signed in to change notification settings - Fork 0
itmajun/python-learn
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Learning Python records
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published