在 Spyder 中注释 Python 代码行的快捷键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36644144/
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-08-19 18:09:54  来源:igfitidea点击:

Shortcut key for commenting out lines of Python code in Spyder

pythonspyder

提问by Kurt Peek

I recently changed from the Enthought Canopy Python distribution to Anaconda, which includes the Spyder IDE.

我最近从 Enthought Canopy Python 发行版更改为 Anaconda,其中包括 Spyder IDE。

In Canopy's code editor, it was possible to comment and uncomment lines of code by pressing the "Cntrl+/" shortcut key sequence. In Spyder I was unable to find an equivalent shortcut key in the introductory tutorial.

在 Canopy 的代码编辑器中,可以通过按“Cntrl+/”快捷键序列来注释和取消注释代码行。在 Spyder 中,我无法在介绍性教程中找到等效的快捷键。

Is there a shortcut key for commenting and uncommenting code in Spyder?

Spyder中是否有注释和取消注释代码的快捷键?

回答by Suresh2692

  • Single line comment

    Ctrl+ 1

  • Multi-line commentselect the lines to be commented

    Ctrl+ 4

  • Unblock Multi-line comment

    Ctrl+ 5

  • 单行注释

    Ctrl+ 1

  • 多行注释选择要注释的行

    Ctrl+ 4

  • 取消屏蔽多行注释

    Ctrl+ 5

回答by Reblochon Masque

On macOS:

在 macOS 上:

Cmd + 1

On Windows, probably

在 Windows 上,可能

Ctrl + (/) near right shift key

回答by jgiles

  • Unblock multi-line comment

    Ctrl+5

  • Multi-line comment

    Ctrl+4

  • 取消阻止多行注释

    Ctrl+5

  • 多行注释

    Ctrl+4

NOTE: For my version of Spyder (3.1.4) if I highlighted the entire multi-line comment and used Ctrl+5the block remained commented out. Only after highlighting a small portion of the multi-line comment did Ctrl+5work.

注意:对于我的 Spyder (3.1.4) 版本,如果我突出显示整个多行注释并使用Ctrl+5块仍然被注释掉。只有在突出显示多行注释的一小部分后才Ctrl+5工作。

回答by Arpit Sharma

Yes, there is a shortcut for commenting out lines in Python 3.6 (Spyder).

是的,在 Python 3.6 (Spyder) 中有注释行的快捷方式。

For Single Line Comment, you can use Ctrl+1. It will look like this #This is a sample piece of code

对于单行注释,您可以使用Ctrl+ 1。它看起来像这样#This is a sample piece of code

For multi-line comments, you can use Ctrl+4. It will look like this

对于多行注释,您可以使用Ctrl+ 4。它看起来像这样

#============= \#your piece of code \#some more code \#=============

#============= \#your piece of code \#some more code \#=============

Note : \represents that the code is carried to another line.

注:\代表代码被带到另一行。

回答by Venkatesan

on Windows F9to run single line

在 Windows F9上运行单行

Select the lines which you want to run on console and press F9button for multi line

选择要在控制台上运行的行,然后按F9按钮进行多行