10.1 从文件中读取数据 10.1.1 读取整个文件 with open(~) as object: contents=object.read() with open('C:/Users/jou/Desktop/input.txt') as file_object: contents=file_object.read() print(contents.rstrip()) 10.1.2 文件路径 #文件路径读取方式1 filepath='C:/Users/jou/Desktop/input…
7.1 函数input()的工作原理 函数input() 让程序暂停运行,等待用户输入一些文本.获取用户输入后,Python将其存储在一个变量中,以方便你使用. message = input("Tell me something, and I will repeat it back to you: ") print(message) Tell me something, and I will repeat it back to you: hello world hello world…
5.1 一个简单示例 cars = ['audi', 'bmw', 'subaru', 'toyota'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title()) Audi BMW Subaru Toyota 5.2 条件测试 每条if 语句的核心都是一个值为True 或False 的表达式,这种表达式被称为条件测试 . 5.2.1 检查是否相等 相等运算符 两个等号(== ) 5.2.2…
4.1 遍历整个列表 4.1.1 深入地研究循环 4.1.2 在for循环中执行更多的操作 4.1.3 在for循环结束后执行一些操作 例 magicians = ['alice', 'david', 'carolina'] for magician in magicians: print(magician.title() + ", that was a great trick!") print("I can't wait to see your next tr…