- strip() 移除字符串头尾指定字符
- https://stackoverflow.com/questions/5319922/python-check-if-word-is-in-a-string 找出一个string里是否含有指定字符,可以用find()函数,但返回值是Index if found and -1 otherwise.
- 关于判定条件的写法 https://stackoverflow.com/questions/1075652/using-the-and-and-not-operator-in-python
- dictionary 定义,添加新key等
- python的调试方法,似乎pdb可以
$python
>>> import pdb
>>> import myCode
>>> pdb.run(myCode.main())
> (1)()
(Pdb)
(Pdb) b main
*** The specified object 'main' is not a function
or was not found along sys.path.
(Pdb) b main()
*** The specified object 'main()' is not a function
or was not found along sys.path.
(Pdb) b sortJumpstart.main()
*** The specified object 'sortJumpstart.main()' is not a function
or was not found along sys.path.
以上关于python debug的方法都行不通,而这篇是我目前见过的最好最清晰的一篇关于pdb debug的,而且照学过程中未出现任何问题: https://www.digitalocean.com/community/tutorials/how-to-use-the-python-debugger
这篇我还没细看,不过或许还可以是上一篇的一点补充吧,不过清晰性可能还是不及上一篇
$: python -m pdb test.py arg1
(-m是引入模块的意思,这里引入pdb模块,即调试模块)
然后一些命令:break, list,continue, next,step,run,help.简写分别为b,l,c,n,s,r,h.打印为p或pp
list可单用,也可加行号,起始行号之间用逗号隔开
设断点的几种方式:
(1) break test.py:5 (按行号设,当pdb在test处时,可以直接写行号)
(2) break test.nested_loop (在函数处设)
(3) break test.py:7, number > 500 (加条件)
break单独使用可以显示断点信息,然后用disable和enable开关断点
- 一个貌似不错的python教学网站: https://www.python-course.eu/dictionaries.php 包含Python 2 Tutorial, Python 3 Tutorial, Advanced Topics, Numerical Python, Machine Learning, Tkinter Tutorial等
- print字典 https://stackoverflow.com/questions/15785719/how-to-print-a-dictionary-line-by-line-in-python
for x in cars:
print (x)
for y in cars[x]:
print (y,':',cars[x][y])
- 文件读写https://www.guru99.com/reading-and-writing-files-in-python.html
- https://www.techwalla.com/articles/how-to-convert-int-to-string-in-python
- https://www.tutorialspoint.com/python/string_split.htm
- https://www.tutorialspoint.com/python/string_strip.htm
- https://stackoverflow.com/questions/4642501/how-to-sort-dictionaries-by-keys-in-python
- https://stackoverflow.com/questions/379906/parse-string-to-float-or-int
- 参数 https://stackoverflow.com/questions/1009860/how-to-read-process-command-line-arguments
f you need something fast and not very flexible
main.py:
import sys
first_name = sys.argv[1]
last_name = sys.argv[2]
print("Hello " + first_name+ " " + last_name )
Then run python main.py James Smith
to produce the following output:
Hello James Smith
https://www.python-course.eu/python3_print.php
https://stackoverflow.com/questions/15286401/print-multiple-arguments-in-python
https://learnpythonthehardway.org/book/ex5.html
https://stackoverflow.com/questions/613183/how-to-sort-a-dictionary-by-value
http://www.jianshu.com/p/0d47cf8577b5
https://docs.python.org/2/library/sets.html
https://stackoverflow.com/questions/1602934/check-if-a-given-key-already-exists-in-a-dictionary
https://stackoverflow.com/questions/28859095/most-efficient-method-to-check-if-dictionary-key-exists-and-process-its-value-if
https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops
https://stackoverflow.com/questions/42315072/python-update-a-key-in-dict-if-it-doesnt-exist
http://blog.csdn.net/roytao2/article/details/54180182
list3=list1+list2
http://blog.csdn.net/promise_love/article/details/46963589
list2=set(list1)
http://blog.csdn.net/duanboqiang/article/details/52945381
from collections import Counter
Counter(list1)
如含中文可加: #coding=utf-8
http://www.runoob.com/python/python-chinese-encoding.html
https://www.python.org/dev/peps/pep-0263/