随笔分类 -  笨办法学Python3

把写的代码已经代码用到的知识总结出来。方便自己复习和别人阅读
摘要:首先简单说一下字符编码的问题。平常遇到比较多的就是ASCII码(全称:美国信息交换标准码)。ASCII码使用一个字节(8位)来表示一些常见的数字、英文字母以及一些控制字符。英语用128个符号编码就够了,但是用来表示其他语言,128个符号是不够的。比如中文汉字就无法用ASCII来表示和编码。为了对世界 阅读全文
posted @ 2020-07-22 11:59 lscv26 阅读(497) 评论(0) 推荐(0)
摘要: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 阅读(227) 评论(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 阅读(271) 评论(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 阅读(209) 评论(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 阅读(203) 评论(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 阅读(356) 评论(0) 推荐(0)
摘要:ex13.py argv参数的学习 1 #argv:参数变量(argument variable),这是一个标准的编程术语,在其他语言中也可可以看到.argument可译为: 参数 2 3 #如果参数是用户在执行命令时就要输入,用argv.命令行参数都是字符串 4 #如果参数是在脚本运行过程中需要用 阅读全文
posted @ 2020-07-17 21:50 lscv26 阅读(287) 评论(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 阅读(201) 评论(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 阅读(374) 评论(0) 推荐(0)