Skip to Content
Learning Python, 3rd Edition
book

Learning Python, 3rd Edition

by Mark Lutz
October 2007
Beginner
752 pages
19h 44m
English
O'Reilly Media, Inc.
Content preview from Learning Python, 3rd Edition

Appendix B. Solutions to End-of-Part Exercises

Part I, Getting Started

See "Part I Exercises" in Chapter 3 for the exercises.

  1. Interaction. Assuming Python s configured properly, the interaction should look something like the following (you can run this any way you like (in IDLE, from a shell prompt, and so on):

    
    % python...copyright information lines...
    >>> "Hello World!"
    'Hello World!'
    >>>                     # Use Ctrl-D or Ctrl-Z to exit, or close window
  2. Programs. Your code (i.e., module) file module1.py and the operating system shell interactions should look like this:

    
    print 'Hello module world!'
    
    % python module1.py
    Hello module world!

    Again, feel free to run this other ways—by clicking the file’s icon, by using IDLE’s Run → Run Module menu option, and so on.

  3. Modules. The following interaction listing illustrates running a module file by importing it:

    
    % python
    >>> import module1
    Hello module world!
    >>>

    Remember that you will need to reload the module to run it again without stopping and restarting the interpreter. The question about moving the file to a different directory and importing it again is a trick question: if Python generates a module1.pyc file in the original directory, it uses that when you import ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python, 6th Edition

Learning Python, 6th Edition

Mark Lutz
Learning Python, 2nd Edition

Learning Python, 2nd Edition

Mark Lutz, David Ascher

Publisher Resources

ISBN: 9780596513986Purchase bookSupplemental ContentErrata Page