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 162 163 164
| print(): print('abc'+abc) print('abc',end='') print('abc','def') print('abc','def',sep=',') print('asdf'+\ 'asdf') print('''asdfasdf asdfasdf asdf''')
"""asdf asdf """
input(): abc=input()
len(): len(abc)
str(): print('abc'+str(1)+'abc')
int(): int('42') int(1.99)
float(): float('3.14')
type(...)
id(...)
if name=='alice': print(...) else: print(...)
if name=='alice': print('abc') elif age<12 print('abc')
break
continue
for i in range(5): for i in range(12,16): for i in range(0,10,2): for i in range(5,-1,-1):
def abc(a): ...
try: ... except ZeroDivisionError: ...
TypeError NameError SyntaxError UnboundLocalError ZeroDivisionError 被0除 KeyboardInterrupt Ctrl-C IndexError 列表 AttributeError KeyError 字典
spam=[['cat','bat'],[10,20,30,40,50]] spam[0] spam=['cat','bat','rat','elephant'] spam[-1] spam[1:3] spam[0:-1] spam[:2] spam[1:] spam[:]==spam len(spam)==4 [1,2,3]+['A','B','C']=[1,2,3,'A','B','C'] del spam[2] spam.index('cat')==1 spam.append(...) spam.insert(1,'chicken') spam.remove('cat') spam.sort() spam.sort(key=str.lower) spam.reverse() list([...])
tuple((...))
mycat={'size':'fat','color':'gray','disposition':'loud'} mycat=dict(size='fat',color='gray',disposition='loud') mycat['size'] list(mycat) for v in spam.values(): for k in spam.keys(): for i in spam.items(): for k,v in spam.items(): spam.get('cups',0) spam.setdefault('color','black')
spam="asdf'asdf" 'abc%s asdf%s asdf'%(name,age) f'asdf{name}asdf{age+1}' spam=spam.upper() spam=spam.lower() spam.isupper() spam.islower() spam.isalpha() spam.isalnum() spam.isdecimal() spam.isspace() spam.istitle() spam.startswith() spam.endswith() 'abc'.join(['1','2','3','4']) '1abc2abc3abc4'.split('abc') 'abcdefghij'.partition('f') 'abcdefghij'.partition('z') 'Hello'.ljust/rjust/center(10) 'Hello'.ljust/rjust/center(20,'=') ' Hello '.strip/lstrip/rstrip() ord() chr()
helloFile=open('...','r',encoding='utf-8') """ 详细说明: 文件必须存在: r 只读,指针在开头 rb 二进制只读,指针在开头 r+ 可读,可从头覆盖 rb+ 二进制读写,指针在开头 文件存在则覆盖,不存在则创建: w 只写 wb 二进制只写 w+ 清空后读写 wb+ 二进制读写 文件存在则指针在末尾,否则创建新文件: a 追加 ab 二进制追加 a+ 读写 ab+ 二进制追加 """ """string""" helloFile.read() """list""" helloFile.readlines() helloFile.write(...) helloFile.close()
try: raise Exception('...') except Exception as err: print('...'+str(err))
assert ...
folder_name=os.path.dirname(__file__)
|