第十章练习10.1
#coding:gbk
#10-1Python学习笔记
filename = 'learning_python.txt'
#没审题...写了个单纯打印三次的程序...
with open(filename) as file_object:
i = 0
content = file_object.read()
while i < 3:
print(content.rstrip())
i = i + 1
with open(filename) as file_object:
content = file_object.read()
#第一次打印:打印全部内容
print(content.rstrip())
with open(filename) as file_object:
#第二次打印:遍历文件对象
for line in file_object:
print(line.rstrip())
with open(filename) as file_object:
#第三次打印:各行存储在列表中
lines = file_object.readlines()
for line in lines:
print(line.rstrip())
#10-2C语言学习笔记
message = "I really like dogs."
print(message.replace('dog','cat'))
with open(filename) as file_object:
content = file_object.read()
print(content.replace('Python','C'))
learning_python.txt
In Python,you can…
你可以进行数字的比对,并进行大量数字的快速比较
你可以通过列表进行数据存储,并由for语句对列表进行遍历。
你可以进行字典的建立,通过键-值对的赋值,可以有效的避免列表顺序混乱的缺点;
你可以通过引入其他程序员的建立好的模块,引入他们编写的函数,从而简化你的代码;
你可以通过基本的if、while、for等语句实现基本的功能实现,从而进一步建立函数;
通过类的建立,能高效的对函数进行功能上的分类,并通过调用实现实例的建立…