《笨方法学Python3》Learn Python 3 The Hard Way ex22 练习22

文章是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 characterComment line, describe what sth does and disable part of the codes
+:plusAdd
-:minusMinus
/: slashDivide
 *: asteriskMultiply
%: percentTake what remains after division
<: less-thanJudge whether the value of the left is less than equal to the one on the right
>: greater-thanJudge whether the value of the left is greater than equal to the one on the right
<=: less-than-equalJudge whether the value of the left is less than equal to the one on the right
>=: greater-than-equalJudge whether the value of the left is greater than equal to the one on the right
 =:equalAssign 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/bracesIndicate 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) 垂直制表符
\000Character 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.argvThe 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 > fileWrite the str into a file
cat file.txtRead the file

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值