1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
""" 多行注释 """
3/2
5//3
'单引号包裹的字符串' "双引号包裹的字符串"
"Hello"[0]
"my name is {}, hello {} ".format("perry","roc")
"my name is {name}, I like {language} ".format(name="perry",language="Python")
li = [1,2,3,4] li.append(5) li.pop() li[1] li[1:3] li[::2] del li[1] 3 in li
tup = (1,2,3,4) tup[0] = 5 a,b,c,d = tup
dic = {"name":"perry", "age":30, "course":"Python"} dic["name"] dic.keys() dic.values() dic.get("name")
s1 = {1,2,3,4,5} s1.add(6) s2 = {3,4,7} s1 & s2 s1 s2 s1 - s2
if 1 == 2: print(" true") else: print(" false")
for i in [1,3]: print("number: {}".format(i))
for i in range(1,3): print("number2: {}".format(i))
i = 0 while i < 3: print(i) i=i+1
def add(x,y): return x+y
add(3,4) add(x=3,y=4)
def func(*args, **kwargs): print(args) print(kwargs)
func(1,2,x=3,y=4)
class Animal(object): type = "Bird"
def __init__(self, name): self.name = name
def fly(self, dest): return "{name} fly to {dest}".format(name=self.name, dest=dest)
@classmethod def getType(cls): return cls.type
@staticmethod def eat(): return "eat something"
bird1 = Animal(name="littel bird")
print(bird1.fly(" ShenZhen"))
bird1.getType()
Animal.type = "Fish" fish1 = Animal(name="littelFish")
print(fish1.getType())
Animal.eat()
import math from math import sqrt from math import * import math as m dir(math)
from functools import wraps
def beg(target_func): @wraps(target_func) def wraper(*args,**kwargs): msg,sayplease = target_func(*args,**kwargs) if sayplease: return "{} {}".format(msg, "Please!")
return msg return wraper
@beg def say(say_please=False): msg = "sit down" return msg,say_please
print(say()) print(say(say_please=True))
|