文章是Zed Shaw编写的Learn Python 3 the Hard Way ex22的答案。本人非编程专业,语言学硕士在读,本帖水平有限。仅抛砖引玉,供大家参考。表格分为三个部分,Function, Symbol, Method。部分内容来自原书,部分内容来自Python Document。只供学习使用。
Function Name | Description |
print() | Print out the content in screen |
round(number[, ndigits]) | Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. |
open() | Open a file, e.g. .txt. |
close() | Close a file |
file.read(size=-1) | Read and return at most size characters from the stream as a single str. If size is negative or None, reads until EOF |
file.readline(size=-1) | Read until newline or EOF and return a single str. If the stream is already at EOF, an empty string is returned. |
file.truncate() | Empty the file |
file.write() | Write stuff to the file |
file.seek(offset[, whence]) | Moves the read/write location to the specified location, e.g. seek(0) is to the beginning of a file. SEEK_SET or 0: seek from the start of the stream (the default); offset must either be a number returned by TextIOBase.tell(), or zero. Any other offset value produces undefined behaviour. SEEK_CUR or 1: “seek” to the current position; offset must be zero, which is a no-operation (all other values are unsupported). SEEK_END or 2: seek to the end of the stream; offset must be zero (all other values are unsupported). |
os.path.exists() | Return Boolean value for the judgement about whether a file exist |
def (*args) | Define a function |
len() | Get the lenth of a str |
Symbol | Description |
#:pound character | Comment line, describe what sth does and disable part of the codes |
+:plus | Add |
-:minus | Minus |
/: slash | Divide |
*: asterisk | Multiply |
%: percent | Take what remains after division |
<: less-than | Judge whether the value of the left is less than equal to the one on the right |
>: greater-than | Judge whether the value of the left is greater than equal to the one on the right |
<=: less-than-equal | Judge whether the value of the left is less than equal to the one on the right |
>=: greater-than-equal | Judge whether the value of the left is greater than equal to the one on the right |
=:equal | Assign the value on the right to the variable on the left |
== | Judge whether the values of two sides are equal |
+= (-=, *=, /=) | x = x + y is the same as x +=y |
"" | String |
f"" | Formatted string, connection with inner {} to seek externale value of variables |
{}:curly brackets/braces | Indicate what has been formatted |
Escape Sequence | |
\\ | Backslash (\) |
\' | Single-quote (') |
\" | Double-quote (") |
\a | ASCII bell (BEL) 响铃 |
\b | ASCII backspace (BS) 退格 |
\f | ASCII formfeed (FF)换页 |
\n | ASCII linefeed (LF)换行 |
\N{name} | Character named name in the Unicode database (Unicode only)输入UNICODE |
\r | Carriage return (CR)回车 |
\t | Horizontal tab (TAB)水平制表符 |
\uxxxx | Character with 16-bit hex value xxxx 值为十六位的十六进制xxxx的字符 |
\Uxxxxxxxx | Character with 32-bit hex value xxxxxxxx值为三十二位的十六进制xxxxxxxx的字符 |
\v | ASCII vertical tab (VT) 垂直制表符 |
\000 | Character with octal value 000 八进制000 |
\xhh | Character with hex value hh 十六进制hh |
Method | Description |
str.format(*args, **kwargs) | Perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces {}. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of the string where each replacement field is replaced with the string value of the corresponding argument. |
sys.argv | The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). |
print(str, end=' ') | Print but not end the line with a newline character |
int(input()) | Get the number as a string from input() |
Powershell command line | |
python -m pydoc ____(function) | ! Must execute in the powershell, equal to help() |
echo str > file | Write the str into a file |
cat file.txt | Read the file |