摘要: 1 def add(a, b): 2 print(f"ADDING {a} + {b}") 3 return (a + b) 4 5 6 def subtract(a, b): #subtract :减去的意思 7 print(f"SUBTRACT {a} - {b}") 8 return a - 阅读全文
posted @ 2020-07-18 12:07 lscv26 阅读(226) 评论(0) 推荐(0)
摘要: 注意,还要在python3,就是ex20.py的同目录里面直接创建一个ex20.txt的文件。里面至少要有三行内容 1 #函数和文件 2 #readline:只读取文本文件的一行 3 #seek(0):将读写位置移动到文件开头 4 from sys import argv 5 script , in 阅读全文
posted @ 2020-07-18 10:22 lscv26 阅读(269) 评论(0) 推荐(0)
摘要: 定义函数的语法: def 函数名(参数) (语句) 1 #函数和变量 2 #函数里的变量与脚本里的变量是没有联系的。 3 def cheese_and_crackers(cheese_count,boxes_of_crackers): 4 print(f"You have {cheese_count 阅读全文
posted @ 2020-07-18 10:15 lscv26 阅读(204) 评论(0) 推荐(0)
摘要: 1 #命名、变量、代码、函数 2 #this one is like your scripts with argv 3 def print_two(*args): 4 arg1, arg2 = args #将参数解包 5 print(f"arg1: {arg1}, arg2: {arg2}") 6 阅读全文
posted @ 2020-07-18 10:11 lscv26 阅读(202) 评论(0) 推荐(0)
摘要: ex15.py 完成ex15.py需要在ex15.py同文件夹目录下面准备一个txt文件(ex15_sample.txt) 执行ex15.py 如: python ex15.py ex15_sample.txt。则可以读取 ex15_sample.txt这个文件的内容 读取文件的基本操作: 打开一个 阅读全文
posted @ 2020-07-18 10:05 lscv26 阅读(355) 评论(0) 推荐(0)