O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Introduction to Python Programming

Próximos SlideShares
Python programming introduction
Python programming introduction
Carregando em…3

Confira estes a seguir

1 de 48 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Introduction to Python Programming (20)


Mais de Akhil Kaushik (19)

Mais recentes (20)


Introduction to Python Programming

  1. 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Python Programming
  2. 2. Python Introduction • Python is a popular programming language. • It was created by Guido van Rossum, and released in 1991. • Python source code is also available under the GNU General Public License (GPL).
  3. 3. Python Introduction • Python is a general-purpose interpreted, interactive, object-oriented and high-level programming language. • Python is designed to be highly readable. • Python has a simple syntax similar to the English language.
  4. 4. Programming….Why?
  5. 5. Type of Languages 1. Binary Level Language 2. Assembly Level Language 3. High Level Language
  6. 6. Need for programming languages? • Closer to human thinking behavior. • Program’s size is shorter. • Error detection is easy. • Same program can be compiled in accordance to different machine architectures.
  7. 7. History • Software for early computers were written in assembly language. • The need of reusability of code gave birth to programming languages. • This need grow huge to overcome the cost restriction of compiler.
  8. 8. Translators
  9. 9. What is a Compiler?
  10. 10. What is a Compiler? Source Language Target Language
  11. 11. Translators - Interpreter • It is another common kind of language processor. • Instead of producing a target program as a translation, it directly execute the operations specified in the source program on inputs supplied by the user.
  12. 12. Translators - Interpreter • This software converts the high-level language into low-level language line by line. • It takes less memory than compiler. • It takes more time than compiler. • It is more efficient in error detection than compiler. • It takes more time to build.
  13. 13. Translators - Interpreter • Java language processors combine compilation and interpretation. • A Java source program may first be compiled into an intermediate form called bytecodes. • The bytecodes are then interpreted by a virtual machine. • A benefit of this arrangement is that bytecodes compiled on one machine can be interpreted on another machine, perhaps across a network.
  14. 14. Translators - Interpreter
  15. 15. Translators - Assembler • This software converts the assembly language (assembly instruction mnemonics) into machine level language (opcodes i.e. 0,1). • It offers reusability of assembly codes on different machine platforms.
  16. 16. Translators - Assembler • It generates instructions by evaluating the mnemonics (symbols) in operation field and find the value of symbol and literals to produce machine code. • Now, if assembler do all this work in one scan then it is called single pass assembler, otherwise if it does in multiple scans then called multiple pass assembler.
  17. 17. Translators - Assembler • Pass-1: – Define symbols and literals and remember them in symbol table and literal table respectively. – Keep track of location counter – Process pseudo-operations • Pass-2: – Generate object code by converting symbolic op-code into respective numeric op-code – Generate data for literals and look for values of symbols
  18. 18. Translators - Assembler
  19. 19. Translators - Linker • A linker is a program that allows a user to link library programs or separate modules of code into their own programs. • It is used to combine different modules of object code into one single executable code program.
  20. 20. Translators - Linker • This may involve combining a program with library programs, or involve recombining blocks of object code from the same program, or a mixture of both. • The linker program is used to recombine the blocks of object code in RAM to get a working full program. • Linker is helpful if there is a shortage of RAM.
  21. 21. Translators - Loader • A loader is a piece of software that chooses exactly where to put object code in RAM, ready for it to be run. • It also adjusts the memory references in programs.
  22. 22. Translators - Loader • Programs can be written by programmers using either ‘absolute addressing’ or ‘relative addressing’. • Relative addressing is more common because then the loader can put the program anywhere in RAM - absolute addressing isn't flexible. • Linker & Loader may overlap.
  23. 23. Translators - Loader
  24. 24. Why Python? • It is used for: – web development (server-side applications), – software development (rapid prototyping), – handling big data and mathematics, – Connecting to database systems, – system scripting.
  25. 25. Why Python? • It supports functional and object oriented programming. • It can be used as a scripting language or can be compiled to byte-code for building large applications. • It provides very high-level dynamic data types and supports dynamic type checking. • It supports automatic garbage collection.
  26. 26. Why Python? • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). • Python has syntax that allows developers to write programs with fewer lines. • Python runs on an interpreter system, which makes prototyping very quick. • It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
  27. 27. Why Python? • The current version is Python 3.8 • Earlier version – Python 2 is quite popular and has frequent security updates. • Some other versions of Python are 1.0, 1.5, 1.6, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7.
  28. 28. Summary - Why Python? • Easy to learn, read and maintain • Broad standard library for all platforms. • Portable & extendable. • Interactive testing & debugging. • Support for all major databases. • Support for GUI applications.
  29. 29. Summary - Why Python? • Python uses new lines to complete a command, instead of ; or {}. • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes.
  30. 30. How to get started? • Usually, Python comes pre-installed in Windows, Linux and Mac OS. • To check, search in the start bar for Python or run the following on the Command Line (cmd.exe): C:UsersYour Name>python --version
  31. 31. How to get started? • Else, we can download python from website: https://www.python.org/ • You can download Python documentation from: https://www.python.org/doc/ • The documentation is available in HTML, PDF, and PostScript formats.
  32. 32. Steps to Install Python on Windows • Open a Web browser and go to https://www.python.org/downloads/. • Follow the link for the Windows installer python-XYZ.msi file where XYZ is the version you need to install. • Save the installer file to your local machine and then run it to find out if your machine supports MSI. • Run the downloaded file. This brings up the Python install wizard, which is really easy to use. Just accept the default settings, wait until the install is finished, and you are done.
  33. 33. Steps to Install Python on Linux • Open a Web browser and go to https://www.python.org/downloads • Follow the link to download zipped source code available for Unix/Linux. • Download and extract files. • Editing the Modules/Setup file if you want to customize some options. • run ./configure script -> make -> make install • This installs Python at standard location /usr/local/bin and its libraries at /usr/local/lib/pythonXX where XX is the version of Python.
  34. 34. Steps to Install Python on Macintosh • Recent Macs come with Python installed, but it may be several years out of date. • See http://www.python.org/download/mac/ for instructions on getting the current version along with extra tools to support development on the Mac.
  35. 35. Setting up Path - Windows • To add the Python directory to the path for a particular session in Windows − • At the command prompt − type path -> Environment Variables -> path -> edit -> %path%;C:Python and press Enter. • Note − C:Python is the path of the Python directory
  36. 36. Setting up Path - Linux • In the csh shell − type setenv PATH "$PATH:/usr/local/bin/python" and press Enter. • In the bash shell (Linux) − type export PATH="$PATH:/usr/local/bin/python" and press Enter. • In the sh or ksh shell − type PATH="$PATH:/usr/local/bin/python" and press Enter. • Note − /usr/local/bin/python is the path of the Python directory
  37. 37. Running Python Code • Interactive Interpreter (write Python or IPython in command prompt) – C:> python • Script from the Command-line (write python code in an editor and save with .py extension, then call interpreter to run it) – C: >python script.py • Integrated Development Environment (IDE)
  38. 38. Python IDEs • Jupyter • Spyder • Thonny • PyCharm • Komodo • NetBeans • &….so plethora of options…
  39. 39. Jupyter Notebook • It is an open-source web application that allows you to create and share documents that may contain: – Data cleaning & transformation, – Equations & numerical simulation, – Data visualizations and narrative text. – Machine learning – Deep learning
  40. 40. Jupyter Notebook • Project Jupyter is a non-profit, open-source project, born out of the IPython Project in 2014. • It supports over 40 languages. • It can also help us share notebooks. • It gives interactive output. • It also does big data integration.
  41. 41. Let’s start writing code…
  42. 42. Let’s start writing code… • Download Anaconda from internet. • I have anaconda 4.4.0 (64-bit). • Write ‘Jupyter’ in the search box -> Jupyter Notebook. • It will start and a new tab will open in your default browser. • Click on “New” dropdown box -> Python3
  43. 43. Let’s start writing code…
  44. 44. Let’s start writing code…
  45. 45. Let’s start writing code…
  46. 46. Keyboard shortcuts - Jupyter Notebook • Shift + Enter run the current cell, select below • Ctrl + Enter run selected cells • Alt + Enter run the current cell, insert below • Ctrl + S save and checkpoint • Ctrl + ] indent • Ctrl + [ dedent • H show all shortcuts • Z undo cell deletion • S Save and Checkpoint • A insert cell above • B insert cell below • X cut selected cells • C copy selected cells • V paste cells below • Shift + V paste cells above • Y change the cell type to Code • M change the cell type to Markdown
  47. 47. First Program
  48. 48. Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!