Python Forum
Adding a paragraph of text before an exercise
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding a paragraph of text before an exercise
#3
(May-05-2018, 06:43 AM)oldDog Wrote: I don't want to add the '#' character because that will comment everything out and only i will be able to see the text.
Comment # is meant for you and other who read your code.

There is way with docstring in function and class.
Then can look at what's in docstring with help() and __doc__.
Example:
def foo():
    '''The meaning of life, the universe, and everything'''
    return 42
Usage:
>>> help(foo)
   
Help on function foo:

foo()
    The meaning of life, the universe, and everything

>>> foo.__doc__
'The meaning of life, the universe, and everything'

>>> foo()
42

Class:
class Bar():
    '''
    This class dos This
    Need to explain more
    '''
    var = 999

    def run(self):
        '''This method do run something'''
        pass
Usage:
>>> Bar.__doc__   
'\n  This class dos This\n  Need to explain more\n  '
Output:
>>> help(Bar) Help on class Bar in module builtins: class Bar(object) | This class dos This | Need to explain more | | Methods defined here: | | run(self) | This method do run something | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | var = 999
Reply


Messages In This Thread
RE: Adding a paragraph of text before an exercise - by snippsat - May-05-2018, 11:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  docx insert words of previuos paragraph on next paragraph in the same position ctrldan 7 1,305 Jun-20-2023, 10:26 PM
Last Post: Pedroski55
  Help adding prompt text in a Layout using Rich TUI Extra 2 1,690 May-23-2022, 07:15 PM
Last Post: Extra
  How to add run in paragraph using python-docx? toothedsword 0 2,818 May-12-2021, 10:55 AM
Last Post: toothedsword
  Adding markers to Folium map only adding last element. tantony 0 2,159 Oct-16-2019, 03:28 PM
Last Post: tantony
  Adding text to plots shaynehansen 0 3,348 Jul-10-2017, 05:54 PM
Last Post: shaynehansen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020