intro.asciidoc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. [[intro]]
  2. == Introduction
  3. Python is one of those rare languages which can claim to be both _simple_ and _powerful_. You will
  4. find yourself pleasantly surprised to see how easy it is to concentrate on the solution to the
  5. problem rather than the syntax and structure of the language you are programming in.
  6. The official introduction to Python is:
  7. __________________________________________________
  8. Python is an easy to learn, powerful programming language. It has efficient high-level data
  9. structures and a simple but effective approach to object-oriented programming. Python's elegant
  10. syntax and dynamic typing, together with its interpreted nature, make it an ideal language for
  11. scripting and rapid application development in many areas on most platforms.
  12. __________________________________________________
  13. I will discuss most of these features in more detail in the next section.
  14. .Story behind the name
  15. **************************************************
  16. Guido van Rossum, the creator of the Python language, named the language after the BBC show "Monty
  17. Python's Flying Circus". He doesn't particularly like snakes that kill animals for food by winding
  18. their long bodies around them and crushing them.
  19. **************************************************
  20. === Features of Python
  21. Simple ::
  22. Python is a simple and minimalistic language. Reading a good Python program feels almost like
  23. reading English, although very strict English! This pseudo-code nature of Python is one of its
  24. greatest strengths. It allows you to concentrate on the solution to the problem rather than the
  25. language itself.
  26. Easy to Learn ::
  27. As you will see, Python is extremely easy to get started with. Python has an extraordinarily simple
  28. syntax, as already mentioned.
  29. Free and Open Source ::
  30. Python is an example of a _FLOSS_ (Free/Libré and Open Source Software). In simple terms, you can
  31. freely distribute copies of this software, read its source code, make changes to it, and use pieces
  32. of it in new free programs. FLOSS is based on the concept of a community which shares
  33. knowledge. This is one of the reasons why Python is so good - it has been created and is constantly
  34. improved by a community who just want to see a better Python.
  35. High-level Language ::
  36. When you write programs in Python, you never need to bother about the low-level details such as
  37. managing the memory used by your program, etc.
  38. Portable ::
  39. Due to its open-source nature, Python has been ported to (i.e. changed to make it work on) many
  40. platforms. All your Python programs can work on any of these platforms without requiring any
  41. changes at all if you are careful enough to avoid any system-dependent features.
  42. +
  43. You can use Python on GNU/Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400,
  44. BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acorn RISC OS, VxWorks, PlayStation, Sharp Zaurus,
  45. Windows CE and PocketPC!
  46. +
  47. You can even use a platform like http://kivy.org[Kivy] to create games for your computer _and_ for
  48. iPhone, iPad, and Android.
  49. [[interpreted]]
  50. Interpreted ::
  51. This requires a bit of explanation.
  52. +
  53. A program written in a compiled language like C or C\++ is converted from the source language
  54. i.e. C or C++ into a language that is spoken by your computer (binary code i.e. 0s and 1s) using a
  55. compiler with various flags and options. When you run the program, the linker/loader software
  56. copies the program from hard disk to memory and starts running it.
  57. +
  58. Python, on the other hand, does not need compilation to binary. You just _run_ the program directly
  59. from the source code. Internally, Python converts the source code into an intermediate form called
  60. bytecodes and then translates this into the native language of your computer and then runs it. All
  61. this, actually, makes using Python much easier since you don't have to worry about compiling the
  62. program, making sure that the proper libraries are linked and loaded, etc. This also makes your
  63. Python programs much more portable, since you can just copy your Python program onto another
  64. computer and it just works!
  65. Object Oriented ::
  66. Python supports procedure-oriented programming as well as object-oriented programming. In
  67. _procedure-oriented_ languages, the program is built around procedures or functions which are
  68. nothing but reusable pieces of programs. In _object-oriented_ languages, the program is built
  69. around objects which combine data and functionality. Python has a very powerful but simplistic way
  70. of doing OOP, especially when compared to big languages like C++ or Java.
  71. Extensible ::
  72. If you need a critical piece of code to run very fast or want to have some piece of algorithm not
  73. to be open, you can code that part of your program in C or C\++ and then use it from your Python
  74. program.
  75. Embeddable ::
  76. You can embed Python within your C/C\++ programs to give _scripting_ capabilities for your
  77. program's users.
  78. Extensive Libraries ::
  79. The Python Standard Library is huge indeed. It can help you do various things involving regular
  80. expressions,documentation generation, unit testing, threading, databases, web browsers, CGI, FTP,
  81. email, XML, XML-RPC, HTML, WAV files, cryptography, GUI (graphical user interfaces), and other
  82. system-dependent stuff. Remember, all this is always available wherever Python is installed. This
  83. is called the _Batteries Included_ philosophy of Python.
  84. +
  85. Besides the standard library, there are various other high-quality libraries which you can find at
  86. the http://pypi.python.org/pypi[Python Package Index].
  87. Summary ::
  88. Python is indeed an exciting and powerful language. It has the right combination of performance and
  89. features that make writing programs in Python both fun and easy.
  90. === Python 2 versus 3
  91. You can ignore this section if you're not interested in the difference between Python 2 and
  92. Python 3. But please do be aware of which version you are using.
  93. Remember that once you have properly understood and learn to use either of them, you can easily
  94. learn the changes between the two versions and adapt easily. The hard part is learning programming
  95. and understanding the core Python language itself. That is our goal in this book, and once you have
  96. achieved that goal, you can easily use Python 2 or Python 3 depending on your situation.
  97. For details on differences between Python 2 to Python 3, see:
  98. - http://lwn.net/Articles/547191/[The future of Python 2]
  99. - https://wiki.ubuntu.com/Python/3[Python/3 page on the Ubuntu wiki]
  100. === What Programmers Say
  101. You may find it interesting to read what great hackers like ESR have to say about Python:
  102. . _Eric S. Raymond_ is the author of "The Cathedral and the Bazaar" and is also the person who
  103. coined the term _Open Source_. He says that http://www.python.org/about/success/esr/[Python has
  104. become his favorite programming language]. This article was the real inspiration for my first brush
  105. with Python.
  106. . _Bruce Eckel_ is the author of the famous 'Thinking in Java' and 'Thinking in C++' books. He says
  107. that no language has made him more productive than Python. He says that Python is perhaps the only
  108. language that focuses on making things easier for the programmer. Read the
  109. http://www.artima.com/intv/aboutme.html[complete interview] for more details.
  110. . _Peter Norvig_ is a well-known Lisp author and Director of Search Quality at Google (thanks to
  111. Guido van Rossum for pointing that out). He says that
  112. https://news.ycombinator.com/item?id=1803815[writing Python is like writing in pseudocode]. He says
  113. that Python has always been an integral part of Google. You can actually verify this statement by
  114. looking at the http://www.google.com/jobs/index.html[Google Jobs] page which lists Python knowledge
  115. as a requirement for software engineers.