# Module 1 ## What are the features of python ? 1. Simple 2. Easy to learn 3. Open source 4. High level Language 5. Dynamically typed 6. Platform independent 7. Procedure and Object oriented ## What are the properties of python? 1. Interpreted: Whatever we write is called as source code, this source code is compiled using a python compiler. Python compiler converts source code to byte code. This byte code is executed by PVM (Parallel Virtual Machine) byte code is converted into machine code for the processor to understand and produce results. ``` Source code --Compiler--> Byte code --PVM--> Machine code --Processor--> Output ``` 2. Huge library: Python has a huge set of library with built in functions which can be imported using "import 'name of library' as 'abbrivation of library's name', ***library is collection of packages*** for example OpenCV, NumPy etc 3. Extensible : Codes written in C and C++ can be integrated in python using PVM, this makes writing codes easier for example code written in java can be integratted using JVM ``` C and C++ codes --PVM--> Python Code ``` 4. Embeddable: we can insert python codes in C and C++ programs, applications are developed in python and then integratted in other languages 5. Database connectivity: Python provides an interface to connect all its program to all majot databases like oracle, MySql, Sybase etc 6. Scalable: **A program is scalable if it could be moved to another OS or hardware and take full advantage of the new environment in terms of performance**. Python programs are scallable 7. Packages: These are subsets of libraries these packages can be imported from certain libraries example: ``` from matplotlib import pyplot as plt over here matplotlib is our library and pyplot is our package ``` ## Python Virtual Machine (PVM) 1. Role of PVM is to converts byte code instructions to machine code and then display final output 2. PVM is equipped with interpretter 3. The processor converts machine code to the final output ## What are the flavors of python? 1. CPython 2. PyPy 3. JPython 4. AnacondaPython ## Frozen Binaries Frozen binaries are a bundles of byte code, PVM and any other supporting file made into a single executable package (.exe) ## Memory Management in python 1. In C and C++ memory allocation and deallocation is done dynamically by the malloc() and free() functions 3. Everything in python is considered as object for example string is considered as object, modules are considered as objects etc 4. All the objects are stored in a seperate memory called as ***heap*** 5. Size of ***heap*** depends on the RAM (Random Access Memory), it can increase-decrease on based of the requirement 1. A module is present in python which is responsible for deleting objects that are not used on program 2. This module represents a garbage truck known as ***gc*** 6. Garbage collector or GC counts the number of time the object has been used and assigns it a referecnce count 7. The objects with the reference count of 0 are removed/freed/deleted --- ## Important libraries: 1. NumPy: This Library is used for processing single and multidimensional arrays 2. Pandas: It is a library for data structures, data analysis, time series and statistics 3. matplotlib: It is used for drawing electronic circuits and 2D graphs --- ## Difference between C and Python | C | Python | | ------------- | ------------- | | C has switch statement | Python doesn't switch statement | | C program is faster | Python program is slower than C | |C has do..while, while and for statement|Python has while and for statement| |C is POP|Python is OOP| |Pointers are available in C|Are not available in python| |Declaration of datatypes is needed|Declaration is not required| |The variable in loop needs to be incremented|The variable in loop increments automatically| |allocation and deallocation of memory needs to be done |Memory allocation-deallocation is done by PVM| |C supports single and multidimensional array|Python needs a third party for it eg: NumPy| |Array Index needs to be positive|Array index can be negative | |Indentation is not required|Indentation is required| |command needs to end with semi colon|Doesn't need semi colon to end a command| |C supports in line assignment|Python does not support in-line assignments|