Triple Quoted Comments (Strings)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Phisatho
Posts: 10
Joined: Mon Jul 18, 2022 9:18 am

Triple Quoted Comments (Strings)

Post by Phisatho » Sat Jul 30, 2022 2:40 pm

Do unassigned triple quoted strings consume memory or are they ignored by the interpreter?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Triple Quoted Comments (Strings)

Post by pythoncoder » Sun Jul 31, 2022 7:46 am

They are ignored.

The way to check this kind of thing is to compile the Unix build. Write a small test script and issue

Code: Select all

./micropython -v -v my_test.py
It will print the bytecode generated.

This is extremely informative.
Peter Hinch
Index to my micropython libraries.

Phisatho
Posts: 10
Joined: Mon Jul 18, 2022 9:18 am

Re: Triple Quoted Comments (Strings)

Post by Phisatho » Sun Jul 31, 2022 7:52 am

Thanks Peter

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Triple Quoted Comments (Strings)

Post by bulletmark » Sun Jul 31, 2022 11:21 pm

The question appears somewhat confused though. All "Unassigned" strings are ignored in Python, not just MicroPython, so perhaps the question is intended to be asking specifically about docstrings? Using mpy-cross shows that docstrings are ignored in MicroPython, but obviously not in Python (unless you specify `python -OO`). Also, any reason triple-quoted strings are distinguised in the question? They are semantically equivalent to single quoted strings with regards to whether unassigned strings or docstrings are ignored or not.

Post Reply