How do i use python interactively?



  • $ python
    Python 3.4.0 (default, Jun 19 2015, 14:20:21) 
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

    The >>> is the prompt, this a good way to try out code, after you quit the it's gone.

    Some very basic commands.

    $ python
    Python 3.4.0 (default, Jun 19 2015, 14:20:21) 
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 2 + 2
    4
    >>> print("Hello World")
    Hello World
    >>> 
    

    Help within interactive python

    >>> help()
    
    Welcome to Python 3.4!  This is the interactive help utility.
    
    If this is your first time using Python, you should definitely check out
    the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.
    
    Enter the name of any module, keyword, or topic to get help on writing
    Python programs and using Python modules.  To quit this help utility and
    return to the interpreter, just type "quit".
    
    To get a list of available modules, keywords, symbols, or topics, type
    "modules", "keywords", "symbols", or "topics".  Each module also comes
    with a one-line summary of what it does; to list the modules whose name
    or summary contain a given string such as "spam", type "modules spam".
    
    help> 
    

    Some help commands

    help> keywords
    
    Here is a list of the Python keywords.  Enter any keyword to get more help.
    
    False               def                 if                  raise
    None                del                 import              return
    True                elif                in                  try
    and                 else                is                  while
    as                  except              lambda              with
    assert              finally             nonlocal            yield
    break               for                 not                 
    class               from                or                  
    continue            global              pass                
    
    help> modules pprint
    
    Here is a list of modules whose name or summary contains 'pprint'.
    If there are any, enter a module name to get more help.
    
    pprint - Support to pretty-print lists, tuples, & dictionaries recursively.
    
    help>
    

    To get a man page output, type just the name of the module, topic, keyword, etc

    help> pprint
    Help on module pprint:
    
    NAME
        pprint - Support to pretty-print lists, tuples, & dictionaries recursively.
    
    MODULE REFERENCE
        http://docs.python.org/3.4/library/pprint
        
        The following documentation is automatically generated from the Python
        source files.  It may be incomplete, incorrect or include features that
        are considered implementation detail and may vary between Python
        implementations.  When in doubt, consult the module reference at the
        location listed above.
    
    DESCRIPTION
        Very simple, but useful, especially in debugging data structures.
    ...
    ...
    

Log in to reply
 

© Lightnetics 2024