摘要: 注意,还要在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)
摘要: ex13.py argv参数的学习 1 #argv:参数变量(argument variable),这是一个标准的编程术语,在其他语言中也可可以看到.argument可译为: 参数 2 3 #如果参数是用户在执行命令时就要输入,用argv.命令行参数都是字符串 4 #如果参数是在脚本运行过程中需要用 阅读全文
posted @ 2020-07-17 21:50 lscv26 阅读(286) 评论(0) 推荐(0)
摘要: ex11.py 1 print("How old are you? ",end = " ") #加入end = " ",则函数不再自动换行 2 age = input() 3 print("How tall are you?",end = " ") 4 height = input() 5 prin 阅读全文
posted @ 2020-07-17 21:35 lscv26 阅读(200) 评论(0) 推荐(0)
摘要: 命名规则 变量名只能包含字母、数字和下划线。变量名可以字母或下划线打头,但不能以数字打头,例如,可将变量命名为message_1,但不能将其命名为1_message 变量名不能包含空格,但可使用下划线来分隔其中的单词。例如,变量名greeting_message可行,但变量名greeting mes 阅读全文
posted @ 2020-07-14 19:16 lscv26 阅读(1301) 评论(0) 推荐(0)
摘要: ex1.py 1 print("hello world!",end = " ")#不换行 2 print("hello again") 3 print("I like typing this.") 4 print("This is fun.") 5 print("Yay!Printing.") 6 阅读全文
posted @ 2020-07-14 17:49 lscv26 阅读(353) 评论(0) 推荐(0)