001.[python学习]写在前面的
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了001.[python学习]写在前面的相关的知识,希望对你有一定的参考价值。
0、多动手写写也许你所说的问题就不是问题;
1、最好的帮助文档是dir和help,如下图:
2、如果为了快速完成任务可以选择IDE,否则尽量不要依赖它,因为它的智能导致自己的无能;
3、也许有其他语言的编程基础和思想,但不要把它强加于你所写的python代码中,否则python只是个外壳的C。
举两个例子,交换两个数字代码比较:
1 >>> a = 10 2 >>> b = 15 3 >>> t = a 4 >>> a = b 5 >>> b = t 6 >>> print a 7 15 8 >>> print b 9 10 10 # 下面方法更简洁 11 >>> a = 10 12 >>> b = 15 13 >>> a, b = b, a 14 >>> print a 15 15 16 >>> print b 17 10
字符串逆序代码比较:
1 >>> s = ‘What Are Words‘ 2 >>> s2 = ‘‘ 3 >>> for c in s: 4 ... s2 = c + s2 5 ... 6 >>> print s2 7 sdroW erA tahW 8 # 第二种方法 9 >>> s = ‘What Are Words‘ 10 >>> print s[::-1] 11 sdroW erA tahW
万事开头难,这是第一篇,下篇先说说pep8
1 >>> import this 2 The Zen of Python, by Tim Peters 3 4 Beautiful is better than ugly. 5 Explicit is better than implicit. 6 Simple is better than complex. 7 Complex is better than complicated. 8 Flat is better than nested. 9 Sparse is better than dense. 10 Readability counts. 11 Special cases aren‘t special enough to break the rules. 12 Although practicality beats purity. 13 Errors should never pass silently. 14 Unless explicitly silenced. 15 In the face of ambiguity, refuse the temptation to guess. 16 There should be one-- and preferably only one --obvious way to do it. 17 Although that way may not be obvious at first unless you‘re Dutch. 18 Now is better than never. 19 Although never is often better than *right* now. 20 If the implementation is hard to explain, it‘s a bad idea. 21 If the implementation is easy to explain, it may be a good idea. 22 Namespaces are one honking great idea -- let‘s do more of those!
以上是关于001.[python学习]写在前面的的主要内容,如果未能解决你的问题,请参考以下文章
写在最前面的话-2017年老男孩最新全栈python第2期学习笔记
机器学习实战3:基于朴素贝叶斯实现单词拼写修正器(附Python代码)
机器学习:基于朴素贝叶斯实现单词拼写修正器(附Python代码)