文档地址 The Hitchhiker’s Guide to Python!
这份文档
| 12 | 目标对象:入门后,有一定基础的Pythonista关键词:最佳实践,Pythonic,各类工具介绍 |
粗粗粗略地过了一遍,大体捞了一些东西出来,大段大段英文太费眼了,回头细读在更新进来
浓缩版,20分钟可大体过完,然后根据自己需要去看详细的吧
整体内容还是很不错的,建议细读英文
PS:文档含有巨量的TODO(没写空白着待补充的),不过但从目录上来看还是很强大滴,相信完善后,会成为一份很牛逼的指南(难度比官方指南高一点点)
链接
不解释,不翻译,自个看….真的没啥(每本入门书籍第一章…)
链接
import 最佳实践
Very bad
| 1234 | [...]from modu import *[...]x = sqrt(4) # Is sqrt part of modu? A builtin? Defined above? |
Better
| 123 | from modu import sqrt[...]x = sqrt(4) # sqrt may be part of modu, if not redefined in between |
Best
| 123 | import modu[...]x = modu.sqrt(4) # sqrt is visibly part of modu\’s namespace |
Python中关于OOP的 观点
Decorators
| 12345678910111213 | def foo(): # do something def decorator(func): # manipulate func return func foo = decorator(foo) # Manually decorate @decoratordef bar(): # Do something# bar() is decorated |
动态类型(Dynamic typing)
Avoid using the same variable name for different things.
Bad
| 1234 | a = 1a = \’a string\’def a(): pass # Do something |
Good
| 1234 | count = 1msg = \’a string\’def func(): pass # Do something |
It is better to use different names even for things that are related, when they have a different type:
| 12345 | Bad items = \’a b c d\’ # This is a string…items = items.split(\’ \’) # …becoming a listitems = set(items) # …and then a set |
可变和不可变类型(Mutable and immutable types)
字符串拼接最佳实践
Bad
粗粗粗略地过了一遍,大体捞了一些东西出来,大段大段英文太费眼了,回头细读在更新进来
浓缩版,20分钟可大体过完,然后根据自己需要去看详细的吧
整体内容还是很不错的,建议细读英文
PS:文档含有巨量的TODO(没写空白着待补充的),不过但从目录上来看还是很强大滴,相信完善后,会成为一份很牛逼的指南(难度比官方指南高一点点)
链接
不解释,不翻译,自个看….真的没啥(每本入门书籍第一章…)
链接
import 最佳实践
Very bad
| 1234 | [...]from modu import *[...]x = sqrt(4) # Is sqrt part of modu? A builtin? Defined above? |
Better
| 123 | from modu import sqrt[...]x = sqrt(4) # sqrt may be part of modu, if not redefined in between |
Best
| 123 | import modu[...]x = modu.sqrt(4) # sqrt is visibly part of modu\’s namespace |
Python中关于OOP的 观点
Decorators
| 12345678910111213 | def foo(): # do something def decorator(func): # manipulate func return func foo = decorator(foo) # Manually decorate @decoratordef bar(): # Do something# bar() is decorated |
动态类型(Dynamic typing)
Avoid using the same variable name for different things.
Bad
| 1234 | a = 1a = \’a string\’def a(): pass # Do something |
Good
| 1234 | count = 1msg = \’a string\’def func(): pass # Do something |
It is better to use different names even for things that are related, when they have a different type:
| 12345 | Bad items = \’a b c d\’ # This is a string…items = items.split(\’ \’) # …becoming a listitems = set(items) # …and then a set |
可变和不可变类型(Mutable and immutable types)
字符串拼接最佳实践
Bad