Python基础语法要点
Python language reserved words:
False elif lambda None else nonlocal True except not and finally or
as for pass assert from raise break global return class if try
continue import while def in with del is yield
The branching structure of a program:
Single branch structure:
if <condition>:<statement block>
Two branch structure:
if <condition>:<statement block 1>
else:<statement block 2>
Multi branch structure:
if <condition 1>:<statement block 1>
elif <condition 2>:<statement block 2>
...
else:<statement N>
The two branch structure has a more concise expression:
<expression 1> if <condition> else <expression 2>
The loop structure of the program:
Traverse loop:
for <loop variable> in <traverse structure>:<statement block>
Infinite loop:
while <condition>:<statement block>
String processing function:
len(x) str(x) chr(x) ord(x) hex(x) oct(x)
Common operators and functions for sequence types:
x in s, x not in s, s + t, s * n, s[i], s[i:j], s[i:j:k]
min(s), max(s), s.index(x[,i[,j]]), s.count(x), len(s)
Operator for collection type:
S - T, S -= T, S & T, S &= T, S ^ T, S ^= T, S | T, S |= T, S <= T, S >= T
The method or operation of a dictionary:
<d>.keys() <d>.values() <d>.items() <d>.get(<key>,<default>) <d>.popitem()
<d>.pop(<key>,<default>) <d>.clear() del <d>[<key>], <key> in <dict>
List type specific functions or methods:
ls[i] = x, ls[i:j] = lt, ls[i:j:k] = lt, del ls[i:j], del ls[i:j:k]
s += t or ls.extend(lt), ls *= n, ls.append(x) ls.clear() ls.copy()
ls.remove(x) ls.insert(i,x) ls.pop(i) ls.reverse(x)
Operation function or method of collection type:
S.add(x) S.clear() S.copy() S.pop() S.discard(x) S.remove(x)
len(S) S.isdisjoint(T), x in S, x not in S
Library programming:
import A
A.b()
from A import b,c
b() + c()
from A import *
b() + c() + d() + ...
<a>.<b>()
File operation function:
<variable name> = open(<file name>,<open mode>)
<variable name>.close()
<file>.readall()
<file>.read(size=-1)
<file>.readline(size=-1)
<file>.readlines(hint=-1)
<file>.write(s)
<file>.writelines(lines)
<file>.seek(offset)
False elif lambda None else nonlocal True except not and finally or
as for pass assert from raise break global return class if try
continue import while def in with del is yield
The branching structure of a program:
Single branch structure:
if <condition>:<statement block>
Two branch structure:
if <condition>:<statement block 1>
else:<statement block 2>
Multi branch structure:
if <condition 1>:<statement block 1>
elif <condition 2>:<statement block 2>
...
else:<statement N>
The two branch structure has a more concise expression:
<expression 1> if <condition> else <expression 2>
The loop structure of the program:
Traverse loop:
for <loop variable> in <traverse structure>:<statement block>
Infinite loop:
while <condition>:<statement block>
String processing function:
len(x) str(x) chr(x) ord(x) hex(x) oct(x)
Common operators and functions for sequence types:
x in s, x not in s, s + t, s * n, s[i], s[i:j], s[i:j:k]
min(s), max(s), s.index(x[,i[,j]]), s.count(x), len(s)
Operator for collection type:
S - T, S -= T, S & T, S &= T, S ^ T, S ^= T, S | T, S |= T, S <= T, S >= T
The method or operation of a dictionary:
<d>.keys() <d>.values() <d>.items() <d>.get(<key>,<default>) <d>.popitem()
<d>.pop(<key>,<default>) <d>.clear() del <d>[<key>], <key> in <dict>
List type specific functions or methods:
ls[i] = x, ls[i:j] = lt, ls[i:j:k] = lt, del ls[i:j], del ls[i:j:k]
s += t or ls.extend(lt), ls *= n, ls.append(x) ls.clear() ls.copy()
ls.remove(x) ls.insert(i,x) ls.pop(i) ls.reverse(x)
Operation function or method of collection type:
S.add(x) S.clear() S.copy() S.pop() S.discard(x) S.remove(x)
len(S) S.isdisjoint(T), x in S, x not in S
Library programming:
import A
A.b()
from A import b,c
b() + c()
from A import *
b() + c() + d() + ...
<a>.<b>()
File operation function:
<variable name> = open(<file name>,<open mode>)
<variable name>.close()
<file>.readall()
<file>.read(size=-1)
<file>.readline(size=-1)
<file>.readlines(hint=-1)
<file>.write(s)
<file>.writelines(lines)
<file>.seek(offset)
上一篇:曹冲称象
下一篇:孤独并非寂寞
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章熱度:★★☆☆☆
文章難度:★★★★★
文章質量:★★★☆☆
說明:系統根據文章的熱度、難度、質量自動認證,已認證的文章將參與打字排名!
本文打字排名TOP20
登录后可见
用户更多文章推荐
- 《三国演义》的结尾诗2024-04-18
- Linux命令练习(终)2024-04-18
- 敕勒歌 (南北朝时期北朝乐府民歌)2024-04-16
- Linux命令练习(三)2024-04-14
- Linux命令练习(二)2024-04-14
- 《物理班》 刘嘉俊 新概念作文2024-04-14
- Linux命令练习(一)2024-04-12
- SQL语句练习(九):SQL与程序协...2024-04-06
- jupyter notebook的快捷键2024-04-06
- 编程语言Ruby的保留字2024-04-01
- SQL Server 2017 Express 常用单词2024-03-16
- SQL语句常用单词和符号2024-03-08
- SQL语句常用单词和符号(三)2024-03-08
- SQL语句常用单词和符号(二)2024-03-07
- 2024政府工作报告极简版2024-03-07
- 橘颂 屈原 楚辞 九章之一2024-03-06
- SQL语句常用单词和符号(一)2024-03-06
- 精灵宝可梦 神奇宝贝 火箭队出场台词2023-11-22
- 8848钛金手机广告台词2023-11-09
- 回到2049 宣传语2023-10-30