r''表示内部的字符串默认不转义'''A...B'''表示多行内容,A后面从新行起#!/usr/bin/env python3
# -*- coding: utf-8 -*-
UTF-8 without BOM编码'%%Hi, my name is %s. I am %d years old' % (houwt, 18)classmates = ['a', b'', 'c']t = (1,)for x in list(rang(5)):
print x
while True:
print 'hello'
d = ['Michael':95, 'Bob':75, 'Tracy':85]
d['Michael']
95
d['Bob'] = 67
#判断key是否存在
'Thomas' in d
d.get('Thomas')
d.get('Thomas', -1)
#删除一个key
d.pop('Bob')
s = set([1, 2, 3])
#s = {1, 2, 3}
s.add(4)
s.remove(4)
| set可以做数学意义上的交集(&)、并集( | )。 |
# abstest.py
# 导入函数form abstest import my_abs
def my_abs(x):
if x >= 0:
return x
else:
return -x
return None
# 空函数
def nop():
pass
for ... in来迭代,应用于任何可迭代的对象,包括list、tuple、dict、str等。list(range(0, 10))
[ x*x for x in range(1, 10)]
lambda x : x * xxxx和__xxx__是公开的,_xxx和__xxx是非公开的数据封装、继承和多态
from enum import Enum导入模块,枚举类成员具有value和name属性