Extended Comments for Python 3?

  • Python
  • Thread starter WWGD
  • Start date
  • Tags
    Python
In summary: I just copied and pasted the following:def Myfunction(): print('hello') and it didn't work. I think what you need is something like this:def Myfunction(): print('hello', end=' ') Which will output 'hello, world'.
  • #1
WWGD
Science Advisor
Gold Member
7,377
11,342
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
  • #2
It should be two keys to the right of the L by using the Shift key.
 
  • Like
Likes WWGD
  • #3
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?
 
  • #4
It seems num lock key does it:

"'''
 
  • #5
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 WWGD
  • #6
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.
 
  • #7
  • Like
Likes WWGD
  • #8
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 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:

FAQ: Extended Comments for Python 3?

What is "Extended Comments" in Python 3?

"Extended Comments" in Python 3 refers to a feature that allows for multi-line comments in code. It is denoted by using triple quotes (''' ''') at the beginning and end of the comment.

How is "Extended Comments" different from regular comments in Python 3?

Regular comments in Python 3 are single-line comments that are denoted by using the hashtag symbol (#). Extended comments, on the other hand, can span multiple lines and are denoted by using triple quotes.

What is the purpose of "Extended Comments" in Python 3?

The purpose of "Extended Comments" in Python 3 is to provide a way for developers to document their code more thoroughly and in a more organized manner. It can also be used for temporarily disabling sections of code without having to delete it.

Are "Extended Comments" necessary in Python 3?

No, "Extended Comments" are not necessary in Python 3. They are merely a helpful feature for developers to better document and organize their code. Regular single-line comments are still sufficient for most cases.

Are there any limitations to using "Extended Comments" in Python 3?

Yes, there are a few limitations to using "Extended Comments" in Python 3. They cannot be nested within each other, and they cannot be used within a string or code block. Additionally, they are not considered as actual code and will not be executed.

Similar threads

Replies
10
Views
2K
Replies
4
Views
1K
Replies
12
Views
7K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
3
Views
693
Replies
4
Views
4K
Replies
15
Views
2K
Replies
8
Views
1K
Replies
3
Views
2K
Back
Top