Python Notes
This section organizes my public notes on Python fundamentals.
Notes / Module
This section organizes my public notes on Python fundamentals.
3 ordinary notes and 1 index note in this branch.
Entrance
The readable index note for this branch stays at its flat canonical URL.
This section organizes my public notes on Python fundamentals.
Notes
Ordinary notes link to their unchanged flat note URLs.
1. 文件是存储在辅助存储器上的一组数据序列,可以包含任何数据内容。 2. 文件包括文本文件和二进制文件两种类. 型。 3. 文本文件和二进制文件的存储方式不同。 4. Python 为源文件指定的默认字符编码是UTF-8 5. 文件的打开方式对应为: ‘r’:只读方式 ‘w’:只写方式,若文件存在,覆盖原来内容 ‘a’:只写方式若文件存在,内容追加在原文件内容后面 ‘t’:文本文件模式 ‘b’:二进制文件模式 ‘x’:创建写模式,文件不存在则创建,存在则返回异常FileEx
random库是Python的标准库,用于产生各种分布的伪随机数序列。 它采用梅森旋转算法生成伪随机数序列。 1. random.random(): 返回随机生成的一个浮点数,范围在[0,1)之间 2. random.uniform(a, b): 返回随机生成的一个浮点数,范围在[a, b)之间 3. random.randint(a,b): 返回随机生成的[a,b]之间的整数 4. random.randrange(a, b, step=c): 在指定范围内,在指定的基数和
核心提要 print() 是 Python 中最常用的内置函数,用于向控制台或文件输出信息。除了把文本显示在屏幕上,它还内置了几个非常实用的控制参数(sep、end、file 等),可以轻松实现数据排版和日志写入。