翻译:
known case of builtins。内建函数,自带函数。
Return the tuple (x//y, x%y) 返回元组 tuple.
Invariant.不变的。
Decimal。十进制
arguments。参数
知识点:
字符串格式化–>%s,%d,%f %号相当于占位符,s,d,f相当于指定类型为str,digit,float
print(“我叫%s 今年%d岁”%(‘json’,18))
变量:小写。a = 3.14159265359
常量:大写。PI = 3.14159265359python无限制,可更改。
函数
def print(self, *args, sep=’ ‘, end=’\n’, file=None): # known special case of print
“”"
print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"""
a = divmod(10, 3)
print(a)
输出
(3, 1)
def divmod(x, y): # known case of builtins.divmod
“”" Return the tuple (x//y, x%y). Invariant: div*y + mod == x. “”"
return (0, 0)
class Decimal(object):
“”“Floating point class for decimal arithmetic.”""
__slots__ = ('_exp','_int','_sign', '_is_special')
# Generally, the value of the Decimal instance is given by
# (-1)**_sign * _int * 10**_exp
# Special values are signified by _is_special == True
# We're immutable, so use __new__ not __init__
def __new__(cls, value="0", context=None):
"""Create a decimal point instance.
>>> Decimal('3.14') # string input
Decimal('3.14')
>>> Decimal((0, (3, 1, 4), -2)) # tuple (sign, digit_tuple, exponent)
Decimal('3.14')
>>> Decimal(314) # int
Decimal('314')
>>> Decimal(Decimal(314)) # another decimal instance
Decimal('314')
>>> Decimal(' 3.14 \\n') # leading and trailing whitespace okay
Decimal('3.14')
"""
import xxx,from xxx import yyy
两种导入模块的方式,一种是import xxx,另一种是from xxx import yyy,第一种仅仅导入一个模块,并且将该模块执行了一遍,if main =="main"里面的没有执行。
同时,有在当前的命名空间中导入变量,需要通过xxx.yyy的方式使用导入模块中的变量、函数、类等;
第二种则将模块中的变量yyy导入了当前命名空间,因此使用时可以直接以yyy调用,使用这种导入方法时,需要注意当前的命名空间是否有重名的,from xxx import *这种方式尽量不要使用,因为这样就破坏了对命名空间的管理。
数据类型