Introduction To Python - Chapter : 1

Vimal Girija VVimal Girija V
6 min read

Python is a high-level, general-purpose programming language that was created by Guido van Rossum and first released in 1991. It has since gained immense popularity among developers due to its simplicity, readability, and versatility. The name Python was selected from the TV show "The Complete Monty Python's Circus", which was broadcast on the BBC from 1964 to 1974

Guido van Rossum: The Father of Python - ENKI Tech

Guido developed Python language by taking almost all the programming features from different languages
--> Functional Programming Features from C
--> Object-Oriented Programming (OOPs) Features from C++
--> Scripting Language Features from Perl and Shell Script
--> Modular Programming Features from Modula-3
Note: Most of the syntax in Python is derived from C and ABC languages

One of the key features of Python is its use of indentation to define code blocks, which promotes clean and well-structured code. It has a large standard library that provides a wide range of modules for various tasks, allowing developers to accomplish many common programming tasks without having to write extensive amounts of code from scratch.

Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. It has a dynamic type system and automatic memory management, which means developers don't need to explicitly declare variable types or manage memory allocation.

Python is known for its extensive third-party libraries and frameworks, which contribute to its versatility. It has libraries for data analysis (e.g., NumPy, Pandas), web development (e.g., Django, Flask), scientific computing (e.g., SciPy), machine learning (e.g., TensorFlow, Scikit-learn), and much more. These libraries make Python a popular choice for various domains, from web development to data science and artificial intelligence.

Applications of Python

Python can be used everywhere. The most common and important application areas are listed below:
--> For developing Desktop Applications
--> For developing Web Applications
--> For developing Database Applications
--> For Network Programming
--> For developing games
--> For Data Analysis Applications
--> For Machine Learning
--> For developing Artificial Intelligence Applications
--> For IoT Applications

buddy4tobuddy

Features of Python

  1. Simple and Easy to Learn:

    --> Python is a simple programming language. When we read a Python program, we can feel like we are reading English statements.
    --> The syntax is very simple, and only 30+ keywords are available.
    --> When compared to other languages, we can write programs with fewer lines. Hence more readability and simplicity.
    --> We can reduce the development cost of the project.

  2. Freeware and Open Source:
    --> Python software can be used without any license, and it's freeware.
    --> Its source code is open, so anyone can customize it based on their requirements.
    E.g., Jython is the customized version of Python to work with Java applications.

  3. High-Level Programming Language:
    --> Python is a high-level programming language, and hence it is a programmer-friendly language.
    --> The programmer is not required to concentrate on low-level activities like memory management, security, etc.

  4. Platform Independence and Portability:
    --> Python's cross-platform compatibility allows it to run on different operating systems, such as Windows, macOS, and Linux.
    --> Python programs can migrate from one platform to another very easily, they provide the same results on any platform.

  5. Dynamically Typed:
    --> In Python, it is not required to declare the type of variables. Whenever the programmer assigns the value, based on the value, the type will be allocated automatically. Hence, Python is considered a dynamically typed language.
    --> But Java, C, etc. are statically typed languages because the programmer has to provide type at the beginning only.
    --> This dynamic typing nature will provide more flexibility to the programmer.

  6. Both Procedure-Oriented and Object-Oriented:
    --> Python language supports both procedure-oriented (like C, Pascal) and object-oriented (like C++, Java) features. Hence, it gets the benefits of both, like security, reusability, etc.

  7. Interpreted:
    --> Python is not required to compile programs explicitly. Internally, the Python interpreter will take care of that compilation.
    --> If compilation fails, the interpreter raises syntax errors. Once the compilation is complete, the PVM (Python Virtual Machine) is responsible for executing.

  8. Embedded:
    --> Python programs can be embedded with any other language program. It will improve the performance of the application.

  9. Extensive Library:
    --> Python has an extensive in-built library
    --> A programmer can use this library directly and is not responsible for implementing the functionality, etc.

Python Versions
--> Python 1.0V was released in January 1994
--> Python 2.0V was released in October 2000
--> Python 3.0V was released in December 2008
Note: Python 3 won't provide backward compatibility with Python 2, i.e., there is no guarantee that Python 2 programs will run in Python 3.

How Does an Interpreter Work?

Interpreter: The Python interpreter is a program that reads and executes Python code, which means that it converts high-level language to low-level machine language. It is the core component of the Python programming language and is essential for the computer to understand the code written by a programmer. Python codes are executed by an interpreter called CPython, which is written in C language and executes instructions in a block of code one line after another.

When you install Python on your computer, it includes the Python interpreter, which provides a command-line interface where you can enter Python code and see the results immediately. This interactive mode is often referred to as the Python REPL (Read-Eval-Print Loop).

To start the Python interpreter, you can open a terminal or command prompt and type python or python3, depending on your Python version. This will launch the interpreter, and you will see a prompt that looks like this >>>, indicating that it is ready to accept Python code.

image-67

Step 1: The translator starts with source code analysis. Here the Python interpreter receives the source code and initializes some instructions to do the following things: check the indentation rule, and check the Python syntax. Maybe there are some incorrect lines, so it will stop the program's execution to show the error message. This phase is called lexical analysis, which means dividing the source code files into a list of tokens

Step 2: Once the parser of the Python interpreter receives the tokens, it starts to manipulate the lexical tokens. It generates a big structure called the AST (Abstract Syntax Tree). The interpreter converts this AST to byte code, which is a machine language. In Python, the byte code can be saved in a file ending with the “.pyc” extension.

Step 3: The Python interpreter initializes its runtime engine called PVM, which is the Python virtual machine. The interpreter loads the machine language with the library modules and inputs it into the PVM. This converts the byte code into executable code such as 0s and 1s (binary) and then it prints the results.

Note: If an error happens during the PVM process, the executor will terminate the operation immediately to display the error.

You can then enter individual Python statements, expressions, or even small programs directly into the interpreter. When you press the Enter key, the interpreter will immediately execute the code and display the output, if applicable.

Next Chapter: Chapter: 2

4
Subscribe to my newsletter

Read articles from Vimal Girija V directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vimal Girija V
Vimal Girija V

Hey there! I'm a passionate tech enthusiast with a diverse skill set in software development, DevOps, and cybersecurity. I love building robust APIs with Python Django and creating interactive user interfaces with React.js. My journey has taken me through the fascinating world of IoT, where I've tinkered with Arduino and Rasberry Pi devices, and I've also delved into the exciting realm of ethical hacking and penetration testing. Technologies I Know: Python Django Framework for API: I have hands-on experience in building APIs using the powerful Python Django framework, enabling me to create scalable and efficient web applications. React.js for Frontend Development: With proficiency in React.js, I craft engaging and responsive user interfaces, making the web experience seamless and enjoyable. Python Automation Testing with Selenium, Pytest, and Appium: My expertise in automation testing using Selenium, Pytest, and Appium ensures that software projects are thoroughly tested, reducing manual effort and improving the overall quality of the code. AWS DevOps with Git, Jenkins, Docker, SonarQube, Terraform, Ansible, Kubernetes, and Maven: I've mastered various DevOps tools and practices on the AWS platform, streamlining the development and deployment process. Git, Jenkins, Docker, SonarQube, Terraform, Ansible, Kubernetes, and Maven are among the tools I'm proficient in. IoT with Arduino and Raspberry Pi: Exploring the Internet of Things world, I've successfully worked with Arduino and Raspberry Pi to build exciting and innovative projects that leverage sensor data and real-world interactions. Certified Ethical Hacking and Penetration Testing: My passion for cybersecurity has driven me to become a Certified Ethical Hacker. I conduct penetration testing to identify and fix security vulnerabilities, ensuring systems and applications are protected against potential threats.