摘要:
1 class Song(object): 2 3 def __init__(self): 4 5 self.lyrics = ["这一路上走走停停,", 6 "顺着少年漂流的痕迹,", 7 "什么也不省心。"] 8 9 ... 阅读全文
摘要:
states = { 'fujian' : 'FJ', 'zhejiang' : 'ZJ', 'jiangsu' :'JS', 'guangdong' : 'GD', 'hunan' : 'HN' } cities = { 'FJ' : '福州', 'ZJ' : '杭州', 'JS' : '南京', 'GD'... 阅读全文
摘要:
1 def start(): 2 print("我们来复习一下西游记或者水浒传的知识吧。") 3 print("实际上也不是什么难题") 4 print("总之,先写一下你要选哪一本吧。") 5 6 choice = input(">") 7 8 if choice == "西游记": 9 xiyouj... 阅读全文
摘要:
from sys import exit def gold_room(): print("This room is full of gold. How much do you take?") #这个房间装满了金币 你要拿多少? choice = input(">>>") if "0" in choice or "1" in choice: h... 阅读全文
摘要:
seek()的三种模式: (1)f.seek(p,0) 移动当文件第p个字节处,绝对位置 (2)f.seek(p,1) 移动到相对于当前位置之后的p个字节 (3)f.seek(p,2) 移动到相对文章尾之后的p个字节 阅读全文
摘要:
1 def cheese_and_crackers(cheese_count, boxes_of_crackers): 2 print(f"You have {cheese_count} cheese!") 3 print(f"You have {boxes_of_crackers} boxes fo crackers!") 4 print("Man that's... 阅读全文
摘要:
# this one is like your scripts with argv def print_two(*args): arg1, arg2 = args print(f"arg1: {arg1}, arg2: {arg2}") # ok, that *args is actually pointless, we can just do this def print_... 阅读全文
摘要:
这个脚本没必要在复制之前问你,也没必要在屏幕上输出那么多东西,试着删掉一些特性,让他看起来更友好。 一行实现 *为什么要在代码中写out_file.close():关闭文件 阅读全文
摘要:
写一段与上个习题类似的脚本,使用read和argv读取你刚刚新建的文件 这个文件中重复的地方太多了,试着用一个target.write()将line1,2和3打印出来,替换原先的六行代码,你可以用字符串 、格式化和转义字符 1 target.write(line1 + "\n" + line2+ " 阅读全文