如何在Python中注释掉一段代码[重复]

本文介绍了在Python中注释代码的不同方法,包括使用 和三引号 。讨论了这些方法的优缺点,如使用 会出现在文档中。还提到了一些编辑器如PyDev、Eclipse、Visual Studio的快捷键支持块注释和取消注释的功能。
摘要由CSDN通过智能技术生成

本文翻译自:How to comment out a block of code in Python [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

Is there a mechanism to comment out large blocks of Python code? 有没有一种机制可以注释掉大块的Python代码?

Right now, the only ways I can see of commenting out code are to either start every line with a # , or to enclose the code in triple quotes: """ . 现在,我可以看到注释代码的唯一方法是使用#开始每一行,或者用三引号括起代码: """

The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. 这些问题是在每行之前插入#很麻烦, """使得我想用作注释的字符串出现在生成的文档中。

After reading all comments, the answer seems to be "No". 阅读完所有评论后,答案似乎是“不”。


#1楼

参考:https://stackoom.com/question/2piE/如何在Python中注释掉一段代码-重复


#2楼

Yes, there is (depending on your editor). 是的,有(取决于你的编辑)。 In PyDev (and in Aptana Studio with PyDev): PyDev中 (以及在带有PyDev的Aptana Studio中 ):

  • Ctrl + 4 - comment selected block Ctrl + 4 - 注释选定的块

  • Ctrl + 5 - uncomment selected block Ctrl + 5 - 取消注释所选块


#3楼

In Eclipse + PyDev , Python block commenting is similar to Eclipse Java block commenting; Eclipse + PyDev中 ,Python块注释类似于Eclipse Java块注释; select the lines you want to comment and use Ctrl + / to comment. 选择要评论的行并使用Ctrl + /进行评论。 To uncomment a commented block, do the same thing. 要取消注释已注释的块,请执行相同的操作。


#4楼

在使用Visual Studio的Python工具的Visual Studio中 ,可以通过Ctrl + KCtrl + C注释掉块,并通过Ctrl + KCtrl + U取消注释。


#5楼

在使用PyDev的 Eclipse中,您可以选择一个代码块并按Ctrl +


#6楼

At least in VIM you can select the first column of text you want to insert using Block Visual mode ( CTRL+V in non-windows VIMs) and then prepend a # before each line using this sequence: 至少在VIM中,您可以使用Block Visual模式(非Windows VIM中的CTRL+V )选择要插入的第一列文本,然后使用此序列在每行之前添加#

I#<esc>

In Block Visual mode I moves to insert mode with the cursor before the block on its first line. 在Block Visual模式下, I移动到插入模式,光标位于第一行的块之前。 The inserted text is copied before each line in the block. 插入的文本在块中的每一行之前复制。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值