Extended Comments for Python 3?

  • Context: Python 
  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Python
Click For Summary

Discussion Overview

The discussion revolves around how to create extended, multi-line comments in Python, focusing on the use of triple quotes and the keyboard input required to type them. Participants explore various methods and share their experiences with formatting issues and software behavior.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Meta-discussion

Main Points Raised

  • One participant expresses difficulty in finding the correct keys for typing triple quotes on a Qwerty keyboard.
  • Another participant suggests that the triple quotes can be found two keys to the right of the 'L' key while using the Shift key.
  • A later reply indicates that the num lock key might be involved in typing the quotes.
  • Some participants clarify that the quotes typed are straight quotes, which may be automatically converted to curly quotes in certain programs like Word.
  • There is a mention of a table listing left and right quotation marks with their corresponding codes.
  • One participant emphasizes that only simple straight double quotes (ASCII 34) are needed for Python, not the curly versions.
  • Another participant notes that the use of triple quotes for comments is not an actual block comment syntax in Python, referencing an external source for clarification.

Areas of Agreement / Disagreement

Participants generally agree on the need for straight quotes in Python, but there is no consensus on the best method for typing them or the nature of triple quotes as comments. The discussion remains unresolved regarding the most effective approach to achieve the desired formatting.

Contextual Notes

Some limitations include the dependence on keyboard layouts, software behavior regarding quote formatting, and the ambiguity surrounding the use of triple quotes in Python.

WWGD
Science Advisor
Homework Helper
Messages
7,806
Reaction score
13,120
Hi All,
I am having trouble figuring out how to do extended, i.e., many-lined, comments. I know the format is ( copied from website):

“”””
Problem is that, while I can find the '' in my Qwerty keyboard, I can't figure out how to find the rest in my keyboard. I assume all Qwertys are the same but if including a pic file of my keyboard helps, please let me know.
TIA.
 
Technology news on Phys.org
It should be two keys to the right of the L by using the Shift key.
 
  • Like
Likes   Reactions: WWGD
Borg said:
It should be two keys to the right of the L by using the Shift key.
Thanks, that gives me the " , but not the ones leaning to the other side.
EDIT2: Would a macro that copied the needed image work?
 
It seems num lock key does it:

"'''
 
WWGD said:
It seems num lock key does it:
"'''
They are just straight quotes when you type them. In some programs like Word, they automatically convert to the left and right versions.
 
  • Like
Likes   Reactions: WWGD
Borg said:
They are just straight quotes when you type them. In some programs like Word, they automatically convert to the left and right versions.
It does happen in Word, you're right. But copying and pasting did not work, unfortunately.
 
  • Like
Likes   Reactions: WWGD
WWGD said:
It does happen in Word, you're right. But copying and pasting did not work, unfortunately.
If you're copying from Word (or a web page), they've already been changed into something else. You should be able to just put straight quotes in python and have it work.
 
  • Like
Likes   Reactions: WWGD
  • #10
DrClaude said:
To be clear: you do not want open and close quotes, just simple "straight" double quotes, ASCII 34.
Also true in C, C++, and many other programming languages.
 
  • #11
DrClaude said:
To be clear: you do not want open and close quotes, just simple "straight" double quotes, ASCII 34.

Note also that the use of triple quotes for comments appears to be a trick, not an actual block comment syntax in python: https://stackoverflow.com/questions/7696924/way-to-create-multiline-comments-in-python
'''
Thanks
'''
EDIT: As a demonstration, and to make up for my Noobishness:
def Myfunction():
print('hello')

'''
Nonsense
'''

Myfunction()

Output in IDLE:
RESTART: C:/Users/.../AppData/Local/Programs/Python/Python37-32/Comment.py
hello
My apologies, I was trying what I read online by using just comments, without any code.
 
Last edited:

Similar threads

Replies
3
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
9K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K