/Doc/tutorial/appetite.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 87 lines · 68 code · 19 blank · 0 comment · 0 complexity · 2e17200d30c4a0a6d062b7d13e846bc5 MD5 · raw file

  1. .. _tut-intro:
  2. **********************
  3. Whetting Your Appetite
  4. **********************
  5. If you do much work on computers, eventually you find that there's some task
  6. you'd like to automate. For example, you may wish to perform a
  7. search-and-replace over a large number of text files, or rename and rearrange a
  8. bunch of photo files in a complicated way. Perhaps you'd like to write a small
  9. custom database, or a specialized GUI application, or a simple game.
  10. If you're a professional software developer, you may have to work with several
  11. C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is
  12. too slow. Perhaps you're writing a test suite for such a library and find
  13. writing the testing code a tedious task. Or maybe you've written a program that
  14. could use an extension language, and you don't want to design and implement a
  15. whole new language for your application.
  16. Python is just the language for you.
  17. You could write a Unix shell script or Windows batch files for some of these
  18. tasks, but shell scripts are best at moving around files and changing text data,
  19. not well-suited for GUI applications or games. You could write a C/C++/Java
  20. program, but it can take a lot of development time to get even a first-draft
  21. program. Python is simpler to use, available on Windows, Mac OS X, and Unix
  22. operating systems, and will help you get the job done more quickly.
  23. Python is simple to use, but it is a real programming language, offering much
  24. more structure and support for large programs than shell scripts or batch files
  25. can offer. On the other hand, Python also offers much more error checking than
  26. C, and, being a *very-high-level language*, it has high-level data types built
  27. in, such as flexible arrays and dictionaries. Because of its more general data
  28. types Python is applicable to a much larger problem domain than Awk or even
  29. Perl, yet many things are at least as easy in Python as in those languages.
  30. Python allows you to split your program into modules that can be reused in other
  31. Python programs. It comes with a large collection of standard modules that you
  32. can use as the basis of your programs --- or as examples to start learning to
  33. program in Python. Some of these modules provide things like file I/O, system
  34. calls, sockets, and even interfaces to graphical user interface toolkits like
  35. Tk.
  36. Python is an interpreted language, which can save you considerable time during
  37. program development because no compilation and linking is necessary. The
  38. interpreter can be used interactively, which makes it easy to experiment with
  39. features of the language, to write throw-away programs, or to test functions
  40. during bottom-up program development. It is also a handy desk calculator.
  41. Python enables programs to be written compactly and readably. Programs written
  42. in Python are typically much shorter than equivalent C, C++, or Java programs,
  43. for several reasons:
  44. * the high-level data types allow you to express complex operations in a single
  45. statement;
  46. * statement grouping is done by indentation instead of beginning and ending
  47. brackets;
  48. * no variable or argument declarations are necessary.
  49. Python is *extensible*: if you know how to program in C it is easy to add a new
  50. built-in function or module to the interpreter, either to perform critical
  51. operations at maximum speed, or to link Python programs to libraries that may
  52. only be available in binary form (such as a vendor-specific graphics library).
  53. Once you are really hooked, you can link the Python interpreter into an
  54. application written in C and use it as an extension or command language for that
  55. application.
  56. By the way, the language is named after the BBC show "Monty Python's Flying
  57. Circus" and has nothing to do with reptiles. Making references to Monty
  58. Python skits in documentation is not only allowed, it is encouraged!
  59. Now that you are all excited about Python, you'll want to examine it in some
  60. more detail. Since the best way to learn a language is to use it, the tutorial
  61. invites you to play with the Python interpreter as you read.
  62. In the next chapter, the mechanics of using the interpreter are explained. This
  63. is rather mundane information, but essential for trying out the examples shown
  64. later.
  65. The rest of the tutorial introduces various features of the Python language and
  66. system through examples, beginning with simple expressions, statements and data
  67. types, through functions and modules, and finally touching upon advanced
  68. concepts like exceptions and user-defined classes.