码迷,mamicode.com
首页 > 编程语言 > 详细

001.[python学习]写在前面的

时间:2016-06-04 01:47:17      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

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 arent 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 youre Dutch.
18 Now is better than never.
19 Although never is often better than *right* now.
20 If the implementation is hard to explain, its a bad idea.
21 If the implementation is easy to explain, it may be a good idea.
22 Namespaces are one honking great idea -- lets do more of those!

 

001.[python学习]写在前面的

标签:

原文地址:http://www.cnblogs.com/tacyeh/p/5557999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!