|
楼主 |
发表于 2021-9-10 22:43:20
|
显示全部楼层
问题总结:
在参考了4楼和9楼的回答后,我查到了这个网站:https://www.geeksforgeeks.org/triple-quotes-in-python/
里面介绍了 """ """ 的作用,其中特别提醒了下面这句话:
Note: Triple quotes, according to official Python documentation are docstrings, or multi-line docstrings and are not considered comments. Anything inside triple quotes is read by the interpreter. When the interpreter encounters the hash symbol, it ignores everything after that. That is what a comment is defined to be.
大致是说,""" """ 和 ''' ''' 这种三引号,属于 docstrings,且不能被认为是注释(comments),括起来的内容会被解释器读取!这一点与5楼(最佳答案)提到的解决方案第2条一致。当然那个网站的文章里还介绍了一下怎么把 """ string""" 当成字符串来使用,大家有兴趣的可以看一看。
至此,现象应该更新成:代码前面如果没有 # 型注释,则代码能在第一行代码的断点处停下(这点我在我的 PyCharm 社区版里是这个情况,与5楼的第一句话的结论有点出入,可能还跟电脑、PyCharm等有关?);如果有 # 型注释,则代码就忽略了第一行代码的断点。
这个问题感觉在实际情况下不太会出现,毕竟不太可能直接只在代码第一行下个断点就不管了,所以我暂时不再纠结这个问题了。
再次感谢大家的回答!
|
|