0% found this document useful (0 votes)
6 views6 pages

Chapter-1 (Python Tutorial)

Python is a widely-used programming language known for its simplicity, readability, and extensive libraries. Created by Guido van Rossum in 1991, it supports multiple programming paradigms and is utilized in various fields such as web development, data science, and machine learning. Python's dynamic typing, interpreted nature, and large community support make it a popular choice among developers.

Uploaded by

mifapawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Chapter-1 (Python Tutorial)

Python is a widely-used programming language known for its simplicity, readability, and extensive libraries. Created by Guido van Rossum in 1991, it supports multiple programming paradigms and is utilized in various fields such as web development, data science, and machine learning. Python's dynamic typing, interpreted nature, and large community support make it a popular choice among developers.

Uploaded by

mifapawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Python

Python is one of the most popular programming languages. It’s simple to use, packed with
features and supported by a wide range of libraries and frameworks. Its clean syntax makes it
beginner-friendly.
Python was created by Guido van Rossum in 1991 and further developed by the Python
Software Foundation. It was designed with focus on code readability and its syntax allows us
to express concepts in fewer lines of code.
Key features of Python
 Easy to Learn and Read:

Python's syntax emphasizes readability, using clear, English-like keywords and indentation
instead of curly braces, making it beginner-friendly.
 Interpreted Language:

Python code is executed line by line by an interpreter, which simplifies debugging and testing.
 Dynamically Typed:

Variable types are determined at runtime, eliminating the need for explicit type declarations
and speeding up development.
 Open Source and Free:

Python is freely available and its source code is accessible for modification and distribution,
fostering a large and active community.
 Large Standard Library:

Python comes with an extensive collection of modules and packages for various tasks,
reducing the need to write code from scratch.
 Object-Oriented Programming (OOP) Support:

Python fully supports OOP principles, allowing for modular and reusable code through
classes and objects. It also supports other paradigms like functional and procedural
programming.
 Platform Independent:

Python code can run on various operating systems (Windows, macOS, Linux) without
modification, thanks to its interpreted nature..
 Large Community Support:

A vast and active global community provides extensive resources, documentation, and
support for Python developers.

 GUI Programming Support:

1|Page
Python offers various toolkits and libraries for creating graphical user interfaces, such as
Tkinter, PyQt, and Kivy.
 Versatility:

Python is used in diverse fields, including web development (Django, Flask), data science
and machine learning (NumPy, Pandas, scikit-learn), automation and scripting, scientific
computing, and more.

Why to Learn Python?


 Python requires fewer lines of code compared to other programming languages.
 Python is in high demand as it provides many job opportunities in Software
Development, Data Science and AI/ML.
 Python provides popular Web Development, AI/ML, Data Science and Data Analysis
Libraries like Django, Flask, Pandas, Tensorflow, Scikit-learn and many more.
 Python is an object oriented programming language which encapsulates code within
object.
 Python is cross-platform which works on Windows, Mac and Linux without major
changes.
 Python is used by big companies like Google, Netflix and NASA.

First Python Program


Here is a simple Python code, printing a string. We recommend you to edit the code and try to
print your own name.
print("Hello World")

2|Page
Output
Hello World
Understanding Hello World Program in Python
Hello, World! in python is the first python program which we learn when we start learning any
program. It’s a simple program that displays the message “Hello, World!” on the screen.
Hello World
Program
Here’s the “Hello World” program:
# This is a comment. It will not be executed.
print("Hello, World!")

Output
Hello, World!

How does this work:


 print() is a built-in Python function that tells the computer to show something on the
screen.
 The message "Hello, World!" is a string, which means it's just text. In Python, strings
are always written inside quotes (either single ' or double ").
 Anything after # in a line is a comment. Python ignores comments when running the
code, but they help people understand what the code is doing.
 Comments are helpful for explaining code, making notes or skipping lines while testing.
We can also write multi-line comments using triple quotes:
"""
This is a multi-line comment.
It can be used to describe larger sections of code.
"""
Indentation in Python
In Python, Indentation is used to define blocks of code. It tells the Python interpreter that a
group of statements belongs to a specific block. All statements with the same level of
indentation are considered part of the same block. Indentation is achieved using whitespace
(spaces or tabs) at the beginning of each line.

3|Page
Example:
if 10 > 5:
print("This is true!")
print("I am tab indentation")
print("I have no indentation")
Explanation:
 The first two print statements are indented by 4 spaces, so they belong to the if block.
 The third print statement is not indented, so it is outside the if block.

Python compilation process


The Python compilation process, while distinct from traditional compiled languages like C++,
involves several key steps that occur primarily at runtime.
 Source Code to Bytecode:
 When a Python program is executed, the Python interpreter first reads the source
code (typically a .py file).
 This source code is then compiled into an intermediate representation called
bytecode. Bytecode is a low-level, platform-independent set of instructions that
the Python Virtual Machine (PVM) can understand.
 During this compilation, syntax errors are checked. If found, the process halts
with an error.
 This bytecode is often saved in .pyc files within a __pycache__ directory for
modules, allowing for faster loading in subsequent executions if the source code
has not changed.
 Bytecode Execution by the Python Virtual Machine (PVM):
 The generated bytecode is then fed to the PVM, which acts as a runtime
environment for Python.
 The PVM interprets and executes the bytecode instructions line by line.
 During this interpretation phase, runtime errors (e.g., type errors, division by
zero) are detected, and execution stops at the point of the error.
 The PVM translates the bytecode into machine-executable instructions specific
to the underlying hardware, allowing the CPU to perform the operations and
produce the program's output.

4|Page
Key Characteristics:
 Runtime Compilation:
Unlike strictly compiled languages, Python's compilation to bytecode happens at runtime, not
as a separate, prior step.
 Portability:
Bytecode's platform-independence means the same .pyc file can run on different operating
systems and architectures, provided a compatible PVM is installed.
 Interpretation:
While a compilation step to bytecode exists, Python is primarily considered an interpreted
language because the PVM interprets and executes this bytecode dynamically.
Famous Application Built using Python
 YouTube: World’s largest video-sharing platform uses Python for features like video
streaming and backend services.
 Instagram: This popular social media app relies on Python’s simplicity for scaling and
handling millions of users.
 Spotify: Python is used for backend services and machine learning to personalize music
recommendations.
 Dropbox: The file hosting service uses Python for both its desktop client and server-
side operations.
 Netflix: Python powers key components of Netflix’s recommendation engine and
content delivery systems (CDN).
 Google: Python is one of the key languages used in Google for web crawling, testing
and data analysis.
 Uber: Python helps Uber handle dynamic pricing and route optimization using
machine learning.
 Pinterest: Python is used to process and store huge amounts of image data efficiently.

5|Page
What can we do with Python?
Python is used for:
 Web Development: Frameworks like Django, Flask.
 Data Science and Analysis: Libraries like Pandas, NumPy, Matplotlib.
 Machine Learning and AI: TensorFlow, PyTorch, Scikit-learn.
 Automation and Scripting: Automate repetitive tasks.
 Game Development: Libraries like Pygame.
 Web Scraping: Tools like BeautifulSoup, Scrapy.
 Desktop Applications: GUI frameworks like Tkinter, PyQt.
 Scientific Computing: SciPy, SymPy.
 Internet of Things (IoT): MicroPython, Raspberry Pi.
 DevOps and Cloud: Automation scripts and APIs.
 Cybersecurity: Penetration testing and ethical hacking tools.

6|Page

You might also like