Page 1 :
i, , , , , , 1.1 Introduction, 1.2 Python — Pluses, , 13 Python — Some Minuses |, 1.4 Worling in Python, , 1.5 Understanding First ProgramiScript, , , , , , r, INTRODUCTION, The word Python — isn’t it scary ? Does it bring the image of big reptile that we prefer to see, either in jungles or zoo ? Well, it’s time to change the image. Now on, you'll remember word, Python for its playfulness and pleasant productivity. Confused ? Well, Don’t be — because, now, on you'll get introduced to a new programming language namely ‘Python’, which promises to, make you a big programming fan :-)., Python programming language was developed by Guido Van Rossum in February 1991., Python is based on or influenced with two programming languages :, , © ABC language, a teaching language created as a replacement of BASIC, and, , © Modula-3, , Python is an easy-to-learn yet powerful object oriented, programming language. It is a very high level programming, language yet as powerful as many other middle-level not so, high-level languages like C, CH, Java etc., , In this chapter, we shall introduce you to playful world of, Piquant Python [Word ‘Piquant’ means pleasantly stimulating, or exciting to the mind]. So, are we ready ? And... here we go.
Page 2 :
COMPUTER SCIENCE WITH PYTHON ~ xi, , — ee, , , , 1.2 PYTHON — PLUSES 4 Easy to Use OO Language, Though Python language came into being in early » Expressive Language, 1990's, yet it is competing with ever-popular + Interpreted Language, languages such as C, C+, Java etc. in popularity + Its Completeness, index. Although, it is not perfect for every type of + Cross-platform Language, application, yet it has many strengths that make it a «» Free and Open Source, good choice for many situations. Let’s see what are & Variety of Usage / Applications, , these pluses of Python., , 1. Easy to Use ; mol . se, Python is compact and very easy to use object oriented language bonea 4 simple syntax rules., It is a very high level language and thus very-very programmer-friendly., , 2. Expressive Language, , Python’s expressiveness means it is more capable to expressing the code’s purpose than many, other languages. Reason being — fewer lines of code, simpler syntax., , For example, consider following two sets of codes :, , // In C++ : Swap Values #In Python : Swap values, int a=2, b=3, tmp; a, b=2,3, tmp =a ; a,b=b,a, | a=b;, b=tmp ;, , | which one is compact and easier to understand ? Need I say more ? :). This is the simplest, example, you'll find many more such examples of Python’s expressiveness in the due course., , | 3. Interpreted Language, , Python is an interpreted language, not a compiled language. This means that the Python, installation interprets and executes the code line by line at a time. It makes Python an, easy-to-debug language and thus suitable for beginners to advanced users., , 4. lts Completeness, , When you install Python, you get everything you need to do real, download and install additional libraries ; all types of required, through various modules of Python standard library*, For example,, such as emails, web-pages, databases, GUI development, network i, , everything is available in Python standard library. Thus, it is ales valle s and many more,, “Batteries Included” philosophy. — Python follows, , work. You do not need to, functionality is available, , for diverse functionality, , 5. Cross-platform Language, , Python can run equally well on variety of platforms ~ Wind, z ., supercomputers, smart phones etc.” Isn’t that amazing ? del 2 ee Macintosh,, cross-platform language. Or in other words, Python is a Portable a es Python a true, , 1. If you install Python through Anaconda Python Distribution it loads most, , libraries ang q, 2. Python even has versions that run on different languages such as Java (} Packages with Python,, , lython), .NET (ronPython) ete.
Page 3 :
Chapter | : GETTING STARTED WITH PYTHON 3, , 6. Free and Open Source, , Python language is freely available i.e., without any cost (from www.python.org). And not only is, it free, its source-code (i.e., complete program instructions) is also available, te., it is, open-source also. Do you know, you can modify, improve/extend an open-source software !, , 7. Variety of Usage/Applications, , Python has evolved into a powerful, complete and useful language over these years. These days, Python is being used in many diverse fields/applications, some of which are :, , , , © Scripting © Rapid Prototyping, © Web Applications _ © GUI Programs, © Game development Database Applications |, , © System Administrations, , 1.3 PYTHON — SOME MINUSES (SO HUMAN LIKE) IMinusesiof Python, , Although Python is very powerful yet simple > Not the Fastest Language, language with so many advantages, it is not the * Lesser Libraries than C, Java, Perl, Perfect Programming language. There are some areas * Not Strong on Type-binding, where Python does not offer much or is not that “+ Not Easily Convertible, , capable. Let’s see what these are :, , 1. Not the Fastest Language, , Python is an interpreted language not a fully compiled one. Python is first semi-compiled into, an internal byte-code, which is then exerted by a Python interpreter. Fully compiled languages, are faster than their interpreted counterparts. So, here Python is little weaker though it offers, faster development times but execution-times are not that fast compared to some compiled, languages., , 2. Lesser Libraries than C, Java, Perl, , Python offers library support for almost all computing programs, but its library is still not, competent with languages like C, Java, Perl as they have larger collections available. Sometimes, in some cases, these languages offer better and multiple solutions than Python., , 3. Not Strong on Type-binding, , Python interpreter is not very strong on catching ‘Type-mismatch’ issues. For example, if you, declare a variable as integer but later store a string value in it, Python won't complain or, pin-point it., , 4. Not Easily Convertible, , Because of its lack of syntax, Python is an easy language to program in. But this advantage has a, flip-side too : it becomes a disadvantage when it comes to translating a program into another, programming language. This is because most other languages have structured defined syntax, Since most other programming languages have strong-syntax, the translation from Python to, another language would require the user to carefully examine the Python code and its structure, and then implement the same structure into other programming language's syntax., , So, now you are familiar with what all Python offers, As a free and open-source language, its, users are growing by leaps and bounds.
Page 4 :
| COMPUTER SCIENCE WITH PYTHON Py, , As per February 2013 popularity index, Python was 4th most popular programmin, after ~ Java, PHP and C#. That is the reason, it’s part of your syllabus. Together, playful Python ;)., , Since Python is an interpreted language and not a compiled language, it would be a, to know the difference between working of an interpreter and a compiler (as ex, following information box)., , 8 language, we'll make it, , 800d idea, Plained jn, , , , Interpreter, , This language processor converts a HLL(High Level Language) program into machine language by, converting and executing it line by line. If there is any error in any line, it reports it at the same time and, program execution cannot resume until the error is rectified. Interpreter must always be present in the memory, every time the program is executed as every time the program is run, it is first interpreted and then executed, For error debugging, interpreter is very much useful as it reports the error(s) at the same time. But once errors, are removed, unnecessary usage of memory takes place as it has to be present in the memory always., , Compiler, , It also converts the HLL program into machine language but the conversion manner is different. It converts, the entire HLL program in one go, and reports all the errors of the program along with the line numbers., After all the errors are removed, the program is recompiled, and after that the compiler is not needed in the, memory as the object program is available., , —— 7] aoe, i COMPILATION 7] INTERPRETATION J, , , , , , After compilation, once the target code is, ready, Compiler is no longer required,, (Because Compiler converts the source code, into executable code in one go), , In interpretation, Interpreter is always, required to interpret and convert, source code as it processes the code, line by line, , , , , , , , , , , , , , , , Python is an interpreted language, that is, all the commands you write are interpreted and executed one by, one., , XN , 3. Source : httpsi//sites.google.com/site/pydatalog/pypl/PyPL-PopularitY-of-Programming-Language.
Page 5 :
Chapter 1: GETTING STARTED WITH PYTHON, , 1.4 WORKING IN PYTHON, , Before you start working i, P ig in Python, you need to i, multiple Python distributions eaitet today. neh nena cee eee, © Default installati i, a “ ' ee available from www.python.org is called CPython installation and, aa ython interpreter, Python IDLE (Python GUI) and Pip (package installer)., er stbUH, ae aot 3 other Python distributions available these days. Anaconda Python, ae a is one such highly recommended distribution that comes preloaded with, 'y packages and libraries (¢.g., NumPy, SciPy, Panda libraries etc.)., © Many popular IDEs are also available e.g., Spyder IDE, PytCharm IDE etc. Of these,, Spyder IDE is already available as a part of Anaconda Python distribution., Ho oe any of these distributions, PLEASE REFER TO APPENDIX A. We shall learn to work, wit! both these distribution types [but my personal favourite is Anaconda ;) — not the reptile, the, Python distribution :)], Once you have Python installed on your computers, you are ready to work on it. You can work, in Python in following different ways :, (i) in Interactive mode (also called Immediate Mode) (ii) in Script mode, , 1.4.1 Working in Default CPython Distribution, The default distribution, CPython, comes with Python interpreter, Python IDLE (GUI based), and pip (package installer). To work in interactive as well as script mode, you need to open, , Python IDLE., , 1.4.1A Working in Interactive Mode (Python IDLE), mmand — one command at a time, and the, , Interactive mode of working means you type the co!, Python executes the given command there and then and gives you output. In interactive mode,, you type the command in front of Python command prompt >>> . For example, if you type 2+5 in, , front of Python prompt, it will give you result as 7 :, , yo 245 4 command/expression giver here, , Result returned, =i):, , by Python, To work in interactive mode, follow the process given below :, (i) Click Start button > All Programs — Python 3.6.x > IDLE, Or, , button — all Programs > Python 3.6.x > Python (command line), , (Python GUI [see Fig. 1.1(a)], , Click Start, , , , Figure 1.1 (a) Starting Python Shell.