我如何流利地使用 Python?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1507041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:26:07  来源:igfitidea点击:

How do I get fluent in Python?

python

提问by Pietro Speroni

Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really Python-ic. What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional programming incorporated; many libraries available; object oriented, and its own ways. In short there are often better, shorter, faster, more elegant ways to the same thing.

一旦您学会了 Python 中的基本命令,您通常能够解决您面临的大多数编程问题。但是这样做的方式并不是真正的Python-ic。常见的是使用经典的c++或Java思维来解决问题。但 Python 远不止这些。它包含了函数式编程;许多可用的库;面向对象,和它自己的方式。简而言之,对于同一件事,通常有更好、更短、更快、更优雅的方法。

It is a little bit like learning a new language. First you learn the words and the grammar, but then you need to get fluent.

这有点像学习一门新语言。首先你学习单词和语法,然后你需要变得流利。

Once you have learned the language, how do you get fluent in Python? How have youdone it? What books mostly helped?

一旦你学会了这门语言,你如何流利地使用 Python?你是怎么做到的?哪些书最有帮助?

回答by FogleBird

Read other people's code. Write some of your own code. Repeat for a year or two.

阅读他人的代码。写一些你自己的代码。重复一两年。

Study the Python documentation and learn the built-in modules.

研究 Python 文档并学习内置模块。

Read Python in a Nutshell.

简而言之,阅读 Python。

Subscribe your RSS reader to the Python tag on Stack Overflow.

为您的 RSS 阅读器订阅 Stack Overflow 上的 Python 标签。

回答by Jon-Eric

Have you read the Python Cookbook? It's a pretty good source for Pythonic.

你读过Python Cookbook吗?这是 Pythonic 的一个很好的来源。

Plus you'll find much more from Alex Martelli on Stack Overflow.

此外,您会在 Stack Overflow 上从 Alex Martelli那里找到更多内容

回答by physicsmichael

I can tell you what I've done.

我可以告诉你我做了什么。

  1. Idiomatic Python
  2. Bookmark SO with the python keyword.
  3. Read other's goodpython code.
  4. The Python Challenge
  1. 惯用的 Python
  2. 使用 python 关键字将 SO 加入书签。
  3. 阅读其他人的好的python 代码。
  4. Python 挑战

That order is probably good, too. This is where things get fun.

这个顺序可能也不错。这就是事情变得有趣的地方。

回答by Alex

More Pythonic? Start with a simple import.

更Python?从一个简单的导入开始。

import this

And add practice.

并添加练习。

回答by Edan Maor

The same way you get fluent in any language - program a lot.

就像您精通任何语言一样 - 大量编程。

I'd recommend working on a project (hopefully something you'll actually use later). While working on the project, every time you need some basic piece of functionality, try writing it yourself, and thenchecking online how other people did it.

我建议在一个项目上工作(希望你以后会实际使用)。在进行项目时,每次您需要一些基本功能时,请尝试自己编写,然后在线查看其他人是如何做到的。

This both lets you learn how to actually get stuff done in Python, but will also allow you to see what are the "Pythonic" counterparts to common coding cases.

这既可以让您学习如何在 Python 中实际完成工作,也可以让您了解常见编码案例的“Pythonic”对应物是什么。

回答by steveha

There are some Python textbooks that not only teach you the language, they teach you the philosophy of the language (why it is the way it is) and teach you common idioms. I learned from the book Learning Pythonby Mark Lutzand I recommend it.

有一些 Python 教科书不仅会教你这门语言,还会教你这门语言的哲学(为什么会这样)并教你常见的习语。我从书中学到学习Python的马克·鲁茨,我推荐它。

If you already know the basics of the language, you can Google search for "Python idioms" and you will find some gems. Here are a few:

如果你已经知道这门语言的基础知识,你可以在谷歌搜索“Python idioms”,你会发现一些宝石。这里有一些:

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

http://docs.python.org/dev/howto/doanddont.html

http://docs.python.org/dev/howto/doanddont.html

http://jaynes.colorado.edu/PythonIdioms.html

http://jaynes.colorado.edu/PythonIdioms.html

If you read some good Python code and get a feel for why it was written the way it was, you can learn some cool things. Here is a recent discussion of modules worth readingto improve your Pythonic coding skills.

如果您阅读了一些优秀的 Python 代码并了解了为什么它是这样编写的,那么您可以学到一些很酷的东西。这是最近关于值得阅读的模块的讨论,以提高您的 Pythonic 编码技能。

Good luck!

祝你好运!

EDIT: Oh, I should add: +1 for Python Cookbookand Alex Martelli. I didn't mention these because Jon-Eric already did.

编辑:哦,我应该添加:+1 表示Python Cookbook和 Alex Martelli。我没有提到这些,因为 Jon-Eric 已经提到了。

回答by Esteban Küber

Read existing projects known for technical excelence.

阅读以卓越技术着称的现有项目。

Some of the ones I'd recommend are:

我推荐的一些是:

回答by TomHastjarjanto

I guess becoming fluent in any programming language is the same as becoming fluent in a spoken/written language. You do that by speaking and listening to the language, a lot.

我想精通任何编程语言与精通口语/书面语言是一样的。你通过说和听语言来做到这一点,很多。

So my advice is to do some projects using python, and you will soon become fluent in it. You can complement this by reading other people's code who are more experienced in the language to see how they solve certain problems.

所以我的建议是用python做一些项目,你很快就会熟练掌握它。您可以通过阅读在该语言方面更有经验的其他人的代码来了解他们如何解决某些问题来补充这一点。