My code doesn't run if I use triple quotes before an else statement:
def do_something(test_option=False):
"""
function to do something
:param test_option: bool
:return: None
"""
'''
Testing
'''
if test_option==True:
print("testing")
'''
Visualization
'''
else:
# do thing
I get a red squiggly under my else.
Why is this?
I understand that ''' can also be used for function annotation. Is it not supposed to be used anywhere else?
Suggestions for alternative ways to highlight organization of code? (My IDE literally highlights ''' in yellow which I have been using organize different sections of my code.)
Triple quotes represent a string literal, not a comment, so by placing the Visualization outside the if block with the same level of indentation you are effectively ending the if statement, so the following else clause becomes invalid. Indent Visualization inside the if block to avoid such an error.
Only use triple-quotes for docstrings (or else other multiline strings, which are rare).
Don't try to use them for comments. Use # your comment goes here...
def do_something(test_option=False):
"""
function to do something
:param test_option: bool
:return: None
"""
# Testing
if test_option==True:
print("testing")
# Visualization
else:
# do thing
(Note by the way that comments are more compact)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With