目录
1 Learn about syntax highlighting and how to get code assistance.
Basic Code Assistance
基本代码辅助
1 Learn about syntax highlighting and how to get code assistance.
1 了解语法突出显示以及如何获得代码帮助。
在这一步中,我们将讨论使用PyCharm的最重要原因之一-代码辅助。
2 Code Completion
2 代码补全
First off, let’s talk about context-aware code completion, where the IDE uses all kinds of smarts to help you finish your typing. Live Templates are one such example. The keyboard shortcut is ⌘J (macOS) / Ctrl+J (Windows/Linux) but PyCharm will invoke them by default when you start typing some code that matches a Live Template. You can find a list of Live Templates in your Preferences/Settings ⌘, (macOS) / Ctrl+Alt+S (Windows/Linux) and you can also add your own.
首先,让我们讨论一下上下文感知代码完成,IDE使用各种智能来帮助您完成输入。Live Templates就是这样一个例子。键盘快捷键是 ⌘J (macOS)/ Ctrl+J (Windows/Linux),但PyCharm会在您开始键入一些与Live Template匹配的代码时默认调用它们。您可以在首选项/设置 ⌘, (macOS)/ Ctrl+Alt+S (Windows/Linux)中找到实时模板列表,也可以添加自己的模板。
PyCharm also offers you basic and type-based smart completion. For example, if we start typing something, PyCharm prompts with options to complete your code, so you won’t need to type the full line. For example, if you have this code in the above class and type in C
, PyCharm will offer you Car
.
PyCharm还为您提供了基本的基于类型的智能完成。例如,如果我们开始键入某些内容,PyCharm会提示选项来完成代码,因此您不需要键入整行。例如,如果你在上面的类中有这样的代码,并输入 C
,PyCharm将为你提供 Car
。
If it’s the correct completion, as it is in this case, we can press Enter, and PyCharm will complete the line for you. If the correct completion is in the list, but not selected, you can use the arrows in your keyboard to go up and down to select it and then press Enter. And finally, if the correct completion is not in the list yes, you can keep typing until PyCharm figures it out for you.
如果它是正确的完成,就像在这个例子中一样,我们可以按Enter键,PyCharm将为您完成这一行。如果正确的完成在列表中,但未选中,则可以使用键盘中的箭头上下移动以选中它,然后按Enter。最后,如果正确的补全不在yes列表中,您可以继续输入,直到PyCharm为您找到为止。
Code completion is not only available