Python入门学习笔记 4.输入输出和读写文件
2019-01-23 10:10
579 查看
4.1 输入输出
接受用户的输入: input()
输入格式:str(), format
Code:
str_1 = input("Enter a string: ") str_2 = input("Enter another string: ") print("str_1 is: " + str_1 + ". str_2 is :" + str_2) print("str_1 is {} + str_2 is {}".format(str_1, str_2))
4.2读写文件
- 写出文件
- 读入文件
some_sentences = '''\ I love learning python because python is fun and also easy to use ''' #Open for 'w'irting f = open('sentences.txt', 'w') #Write text to File,没有输出绝对路径的话,默认在当前目录下创建。 f.write(some_sentences) f.close() #If not specifying mode, 'r'ead mode is default f = open('sentences.txt') while True: line = f.readline() #Zero length means End Of File if len(line) == 0: break print(line) # close the File f.close
相关文章推荐
- 简明Python教程学习笔记_7_输入输出和文件操作
- NetworkX学习笔记-3-Python中输出Gephi文件格式的方法
- Python菜鸟学习手册10----文件的输入与输出
- C++ Primer 学习笔记_26_标准I/O库(续) --文件的输入与输出、字符串流
- iMOOC学习笔记:Java的Excel读写操作入门实践-利用POI解析Excel文件(二)
- python基础教程学习笔记---(6)文件读写
- Python 学习笔记之八——输入和输出
- Python3学习笔记7-文件的读写
- 2012/2/11 《C++ Primer Plus》第十七章:输入、输出和文件 学习笔记
- 从入门到精通Python学习第十五课:输入与输出
- C++学习笔记之输入、输出和文件
- Python学习笔记(三):Time、函数、模块、文件I/O、异常处理(快速入门篇)
- NetworkX学习笔记-3-Python中输出Gephi文件格式的方法
- python学习-文件的输入输出
- Python学习笔记(3)--数据文件的读写
- 转 C++学习笔记 之输入输出和文件
- python学习笔记(2):输入与输出
- Python学习笔记二(Python程序输入/输出)
- Python零基础入门学习之输入与输出
- python学习笔记----python输入与输出和注释