![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python初学记录
PandaDou
啥都别说了,学吧......
展开
-
Command Line Crash Course Day1
Windowslist of commands:pwd: print working directorymkdir: make directory (mkdir temp) ( mkdir temp/stuff ) ( mkdir "I Have Fun" )cd: change directory...原创 2018-04-18 22:47:02 · 133 阅读 · 0 评论 -
Exercise39: python字典(访问,操作,list(), dirt.items(), dirt.get() )
ex39.py打印:1、字典:可存储任意类型的对象,格式形如下:2、字典的访问:dic[key]3、修改字典元素: (1)修改已有键值,例子:打印 (2)添加新的键值,例子: 打印: ...原创 2018-05-12 11:01:24 · 1000 阅读 · 0 评论 -
关于TypeError: object() takes no parameters
原创 2018-05-13 10:52:37 · 173 阅读 · 0 评论 -
Exercise40(modules, classes, objects)
ex40.py原创 2018-05-16 15:55:23 · 154 阅读 · 0 评论 -
python var1, var2 = var2, var1
1、变量一和变量二交换值可以使用var1, var2 = var2, var1。2、变量一和变量二可以不是同种类型的变量。。测试1:测试2:测试3:测试4:测试5...原创 2018-05-16 19:42:57 · 6526 阅读 · 5 评论 -
python random函数
调用random前要import random模块。测试:1、random.random() : 生成一个随机的浮点数,在0 ~ 1之间2、random.sample() : 从指定的序列或列表中, 随机的截取指定长度的片段。测试1(序列):测试2(列表):3、random.randint() : 随机生成一个int类型的数,可以指...原创 2018-05-18 15:58:56 · 31598 阅读 · 2 评论 -
python urlopen()
首先调用urlopen需要导入urllib.request模块。urllib.request :urlopen() : 简单来说就是打开一个URL.url : 来自百度百科urlopen的返回值,测试:可见返回值是http.client.HTTPResponsed对象。http.client.HTTPResponsed对象:详...原创 2018-05-19 09:34:35 · 4775 阅读 · 0 评论 -
python dic.keys()
keys 是对字典的操作,返回字典的key值。测试:打印:原创 2018-05-19 10:35:03 · 5496 阅读 · 0 评论 -
python capitalize()
作用: 返回一个字符串,首字母为大写,其他字母为小写。所以它capitalize()返回的是str的一个副本,这个副本的特点是首字母大写,其余字母小写,并不改变str。测试1:测试2:测试3:...原创 2018-05-19 11:06:34 · 1302 阅读 · 0 评论 -
python count
测试1(字符串):测试2(列表):测试3(元组):结论: 存在列表和字符串有count属性,元组无。使用count可以得到字符串中某字符串的数量。或某列表中元素的数量。...原创 2018-05-19 12:21:33 · 652 阅读 · 0 评论 -
python3 range
python 3 range()的返回值原创 2018-05-19 15:42:54 · 459 阅读 · 1 评论 -
简单理解python if __name__ == '__main__'
1、准备两个.py文件, 其中一个导入另一个。如下图所示。test1.pytest2.py可见test2.py导入了test1.py2、运行test2.py可见, 我们导入的test1.py,在我们没有调用它的函数时,它也运行了。为解决类似的问题,需要用到if __name__ == '__main__' 。3、现在将 if __name__ ...原创 2018-05-20 11:45:28 · 144 阅读 · 0 评论 -
简单理解python super()
作用: 在子类中调用父类的方法。测试:打印:super()通过 __mro__ 来决定子类继承父类方法时的顺序。在原代码中加入打印mro表:关于mro(Method Resolution Order) : 方法解析顺序, 牵扯C3算法。一篇文档:https://www.python.org/download/releases/2.3/mro/...原创 2018-05-20 16:52:31 · 297 阅读 · 0 评论 -
python dedent
例子:打印:原创 2018-05-21 09:53:22 · 6215 阅读 · 0 评论 -
python get
(https://docs.python.org/3/library/stdtypes.html#mapping-types-dict)测试:原创 2018-05-21 10:07:22 · 145 阅读 · 0 评论 -
关于TypeError: 'tuple' object is not callable
分析:callable 是可调用的意思,只有函数是可以被调用的, 元组对象谈不上调用。由上图可见,在打印tuple x的第一个元素时, 要用x[0], 而不能用x(0)...原创 2018-07-05 10:14:59 · 16655 阅读 · 4 评论 -
lpthw ex49解析关键词
在类Zork类游戏中,玩家的输入常常不是固定的,甚至可以有语法错误,但是程序不能因此卡到这里,中断是最差劲的,不停的提示异常也很烦,程序仍要做出决定,所以需要解析关键词。 比如我想表达,我要往南方走,我的表述可以是以下(甚至有语法错误): i will go north i will go to the north go ...原创 2018-07-05 20:11:59 · 288 阅读 · 0 评论 -
Exercise38 (split, pop, tuple(元组), len, append, join, stuff[0], stuff[-1])
ex38.py复习:1、split()作用: 把string按照相应规则打断,储存在一个列表里。例1:默认参数空格打印:例2:自选参数打印:2、tuple(元组)元组与列表相似,不过元组的元素不能修改,用小括号,格式如下:3、len()作用: 返回对象(字符、列表、元组)长度或项目个数例子:打印:...原创 2018-05-11 09:54:14 · 356 阅读 · 0 评论 -
python try语句相关(try/except/else/finally)
1、try - except作用: 捕获程序在执行时遇到的异常情况,即一些报错。什么啥玩意儿没定义啊,符号又错了啊之类的你懂得。意义: 因为程序在发现某个错误时,往往会中断不再向下执行,如下例子说明问题:很明显,我们并没有定义b, 就将它赋值给a, 现在我们运行如下:不出所料提示NameError, 发现错误就报错,不再执行下面的程序。现在我们用try/except写...原创 2018-05-09 22:11:19 · 140563 阅读 · 34 评论 -
Exercise36(my "Zork")
ex36_my_game.py仿写的ex35.py, 没有写完,不过框架有了。。。灵感是我怎么追上自己女朋友的。。。我的地图:原创 2018-05-09 09:23:29 · 173 阅读 · 0 评论 -
Command Line Crash Course Day2
windowsrmdir : remove directory rmdir <dir>pushd : push directory ( save where i am, then go here )pushd i/love/qjpopd : pop directory (takes the last ...原创 2018-04-19 17:38:49 · 107 阅读 · 0 评论 -
a list of commands
windowspwd : print working directoryhostname : my computer's network namemkdir : make directorycd : change directory...转载 2018-04-19 17:51:47 · 304 阅读 · 0 评论 -
Exercise 1、2、3
python ex1.py1、不像C后面要加;号。2、单、双引号效果一样。3、单引号里面的双引号可以被打印(反过来亦可)。SyntaxError: grammar errorpound character、octothorpe、hash: #(comment)python ex2.pypython ex3.py1、print里可...原创 2018-04-22 10:53:44 · 353 阅读 · 0 评论 -
Exercise 4、5、6、7、8、9
ex4.pyemmmm不用先定义变量名称,直接变量赋值一步到位。ex5.py1、have variable embedded in strings :f"Hello {somevar}"。2、如果不加f,将直接打印{stuffs}。3、round(): 四舍五入得一个整数。4、{}里可以做算数运算。ex6.py1、.for...原创 2018-04-23 15:05:27 · 186 阅读 · 0 评论 -
Exercise10、11
ex10.py1、Escape Sequences : 转义字符2、\n : 换行3、\t : tab4、\\ : print \5、\"(') : print " or 'ex11.py1、end=' ' : Tells print to not end the line with a new line.2、input( ) : get ...原创 2018-04-24 21:30:01 · 152 阅读 · 0 评论 -
Exercise13、14、15(repr)
ex13.py如果输入的参数不够会有以下报错:1、argv : input on the command line, like2、input( ) : using the keyboard while the script is running.3、ls ex1*.py4、 from sys import argv5、repr( )ex14.py...原创 2018-04-25 10:22:21 · 89 阅读 · 0 评论 -
Exercise16、17
ex16ex17原创 2018-04-28 08:43:39 · 85 阅读 · 0 评论 -
Exercise18、19、20、218(自定义函数, 操作文件相关函数)
ex18.pyex19.pyCan give function straight numbers, variable, math, combine math and variable.ex20.pyex20_test.py1、current_file = open(input_file),print current_file...原创 2018-04-30 10:45:38 · 163 阅读 · 0 评论 -
Exercise22(操作文件的函数以及一些符号)
ex22_list.txtprint("something") # show something on the terminalprint("age: ", 23)print("age: ", 20 + 3)print("age: ", age)print(f"age: {age}")print("age: { }".format('23'))round() ...原创 2018-05-01 10:53:34 · 249 阅读 · 0 评论 -
Exercise23(utf-8, encode, decode, import sys, from sys import, strip,$OutputCod, chcp 65001)
ex23.py输出节选:......进入python:1、python3默认utf-8.2、.encode() : encode string to bytes .decode() : decode bytes to string3、utf-8中文的编码问题:吴的utf-8编码为:E590BE语的utf-8编码为:E8A...原创 2018-05-02 17:15:26 · 278 阅读 · 1 评论 -
Exercise24、25(return一个元组, split, sorted, pop, help, triple-quotes)
ex24.pysecret_formula(started)函数的返回值为jelly_beans, jars, crates所以它到底是个啥,然后是这么个东西:这是个元组, 元素不可修改。结论: return 几个值, 相当于返回了一个包含这些元素的元组。ex25.py一:函数清单:(1)split()(2)...原创 2018-05-03 15:20:40 · 162 阅读 · 0 评论 -
Exercise29、30、31(logic list, if-statement(if/elif/else), python的缩进 )
ex27logic list:andornot!===>=<=TrueFalseTrue or True == TrueTrue or False = FalseFalse or False = Fals...原创 2018-05-06 15:57:06 · 148 阅读 · 0 评论 -
Exercise32(for-loop, range, apend, extend)
ex32.py1、for-loop2、range()3、apend()关于range() :返回值:结构为[start, start + step, start + step *2, ...]的整数序列。语法: range(stop) 和 range(start, stop[, step])注意:1、range(stop) 等价于range(0,...原创 2018-05-07 12:00:21 · 157 阅读 · 0 评论 -
关于python的lists
1、list的访问(1)访问某一个元素(2)访问一段元素(list[x:y],及 x to y)(3)(4)2、增加list元素(1)使用append()函数(2)使用extend()函数3、删减list元素使用del语句:4、list操作符(1)+(组合) (2)len()(长度)...原创 2018-05-07 16:06:59 · 264 阅读 · 0 评论 -
Exercise33(append, while-loops, def, input, for-loops)
ex33.pyConvert this while-loop to a function that you can call, and replace 6 in the test (i < 6) with a variable.注意: 如果直接amount = input(),则amount是字符,在while中不能与数字做比较会报错,如下:所以应该用amount...原创 2018-05-07 22:27:52 · 134 阅读 · 0 评论 -
Exercise35('character' in string, exit(0) )
ex35.py关于‘character’in string的用法:exit(0) : 正常退出程序。原创 2018-05-08 11:14:58 · 113 阅读 · 0 评论 -
plt.show()没有图片
python3.7在python下查询backend:>>>>matplotlib.get_backend()若为Agg, 可以改成TkAgg(还没顾上搞懂为啥,赶进度,解决问题先)(1)apt-get install tk-dev(2)vim /etc/matplotlibrc修改即可。...原创 2018-11-19 22:50:36 · 6364 阅读 · 0 评论