基础语法 输入和输出 代码中要修改不可变的数据会出现什么问题,抛出什么异常? 代码不会征程运行,抛出TypeError异常 a = 1,b = 2,不用中间变量交换a和b的值? # 方法1 a = a + b b = a - b a = a -b #方法2: a = a^b b = b^a a = a^b #方法3 a,b = b, a print调用python中底层的什么方法? print方法默认调用sys.stdount.write方法,即往控制台打印字符串 下面这段代码的输出结果是什么?…
python中也有文件读写,通过调用内置的读写函数.可以完成文件的打开/关闭.读.写入.追加等功能. open()函数 open()函数为python中的打开文件函数,使用方式为: f = open("[文件绝对路径]",'[文件使用模式') 以 f = open('/home/user/lina/info_lina.txt','r')为例,我们在linux环境中以r(只读模式)打开/home/user/lina/info_lina.txt的文件,此处路径也可以为相对路径,相对于本程序…
(1)路径问题 open一个同py文件同一个目录的文件的时候,用以下: txt = open('/filtered_words.txt','rb') words = txt.readline() filtered = [] for word in words: filtered.append(word) txt.close() print(filtered) 会报错 FileNotFoundError: [Errno 2] No such file or directory: '/filtere…