- Select a fragment of source code.
- On the main menu, choose , or press Ctrl+Alt+T.
- Select the desired folding comments from the list:

PyCharm surrounds the code fragment with comments observing the syntax of the current language.
- If necessary, change description of the code fragment to be folded:

You can now collapse or expand the code.
When collapsed, the code is concealed behind the description, and you can view it by hovering your mouse pointer over the description:

