Python早期学习的重要语言功能(惯用语)是什么 [英] What are the important language features (idioms) of Python to learn early on

查看:76
本文介绍了Python早期学习的重要语言功能(惯用语)是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会对了解StackOverflow社区认为Python的重要语言功能(惯用语)感兴趣.将程序员定义为Pythonic的功能.

I would be interested in knowing what the StackOverflow community thinks are the important language features (idioms) of Python. Features that would define a programmer as Pythonic.

Python(Pythonic)惯用语-语言"Python"的自然或特征性的代码表达式".

Python (pythonic) idiom - "code expression" that is natural or characteristic to the language Python.

另外,所有Python程序员都应该早点学习哪些习语?

预先感谢

相关:

推荐答案

Python是一种可以描述为的语言:

Python is a language that can be described as:

"规则,您可以在您的手掌上有一个巨大的袋子钩子".

"rules you can fit in the palm of your hand with a huge bag of hooks".

Python中几乎所有内容都遵循相同的简单标准.一切都可以访问,更改和调整.语言层元素很少.

Nearly everything in python follows the same simple standards. Everything is accessible, changeable, and tweakable. There are very few language level elements.

例如,内置len(data)函数. len(data)的工作原理是简单地检查 data .__ len __()方法,然后调用它并返回值.这样, len()可以在实现 __ len __()方法的任何对象上工作.

Take for example, the len(data) builtin function. len(data) works by simply checking for a data.__len__() method, and then calls it and returns the value. That way, len() can work on any object that implements a __len__() method.

首先了解类型和基本语法:

Start by learning about the types and basic syntax:

  1. 动态强类型语言
  2. 布尔,整数,浮点数,字符串,列表,元组,字典,集合
  3. 陈述,缩进,一切都是对象"
  4. 基本功能定义

然后继续学习python的工作原理:

Then move on to learning about how python works:

  1. 导入和模块(真的很简单)
  2. python路径(sys.path)
  3. dir()函数
  4. __ builtins __

一旦您了解如何将各个部分组合在一起,请返回并介绍一些更高级的语言功能:

Once you have an understanding of how to fit pieces together, go back and cover some of the more advanced language features:

  1. 迭代器
  2. __ len __ 这样的替代(有很多)
  3. 列表理解和生成器
  4. 类和对象(同样,一旦您知道一些规则,就非常简单)
  5. python继承规则

一旦您对这些项目感到满意(重点是使它们变成蟒蛇皮的东西),请查看更具体的项目:

And once you have a comfort level with these items (with a focus on what makes them pythonic), look at more specific items:

  1. Python中的线程(请注意全局解释器锁)
  2. 上下文管理器
  3. 数据库访问
  4. 文件IO
  5. 插座
  6. 等...


永远不要忘记 Python的禅宗(作者蒂姆·彼得斯)

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

这篇关于Python早期学习的重要语言功能(惯用语)是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆