Python 模块
Python 输入和输出
代码区:
# 包 # 点模块名称 # A.B 表示包A中的子模块B # 几种导包方式 import sound.effects.echo; form sound.effects import echo; form sound.effects import *; ########################### s = ‘erbaohuadou‘; print(s); # erbaohuadou print(repr(s)); # ‘erbaohuadou‘ print(str(1/7)); # 0.14285714285714285 print(1/7); # 0.14285714285714285 x = 5 * 3.25; y = 200 * 200; s = ‘The value of x: ‘ + repr(x) + ‘the value of y: ‘ + repr(y) print(s); # The value of x: 16.25the value of y: 40000 print(‘狗狗的名字{}二宝的名字{}‘.format(‘huadou‘, ‘erbao‘)); # 狗狗的名字huadou二宝的名字erbao print(‘狗狗的名字{1}二宝的名字{0}‘.format(‘erbao‘, ‘huadou‘)); # 狗狗的名字huadou二宝的名字erbao print(‘狗狗的名字{dogName}二宝的名字{rabName}‘.format(rabName=‘erbao‘, dogName=‘huadou‘)); # 狗狗的名 字huadou二宝的名字erbao import math; print(‘圆周率值:{}‘.format(math.pi)); # 圆周率值:3.141592653589793 print(‘圆周率值:{!r}‘.format(math.pi)); # 圆周率值:3.141592653589793 print(‘圆周率值:{0:.3f}‘.format(math.pi)); # 圆周率值:3.142 # 格式化数字、表格 table = {‘item1‘: 4578, ‘item2‘: 7244, ‘item3‘: 2344}; for name,phone in table.items(): print(‘{0:10}==>{1:10d}‘.format(name, phone)); # 读写文件 f = open(‘test.txt‘, ‘r+‘); print(f.read()); # print(f.write(‘this is a text.‘)); # 15 print(f.tell()); # 118 print(f.close()); # None
时间: 2024-11-06 11:22:30