0% found this document useful (0 votes)
4 views5 pages

Python

Python is a high-level, general-purpose programming language known for its readability, simplicity, and versatility, supporting multiple programming paradigms including object-oriented, procedural, and functional programming. It features an extensive standard library, dynamic typing, and automatic memory management, making it suitable for various applications. Python's data structures, such as lists and tuples, offer flexibility in data storage, while its packages facilitate working with different data formats and network protocols.
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)
4 views5 pages

Python

Python is a high-level, general-purpose programming language known for its readability, simplicity, and versatility, supporting multiple programming paradigms including object-oriented, procedural, and functional programming. It features an extensive standard library, dynamic typing, and automatic memory management, making it suitable for various applications. Python's data structures, such as lists and tuples, offer flexibility in data storage, while its packages facilitate working with different data formats and network protocols.
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, as a high-level, general-purpose programming language, possesses several key features that
contribute to its popularity and versatility:

• Readability and Simplicity: Python emphasizes code readability with its clear, concise syntax
and the use of significant indentation instead of braces, making it easier to learn and
maintain.

• Interpreted Language: Python code is executed directly by an interpreter, line by line, rather
than being compiled into machine code beforehand. This facilitates faster development
cycles and easier debugging.

• Dynamically Typed: Variable types in Python are determined at runtime, meaning explicit
type declarations are not required. This offers flexibility but necessitates careful handling to
avoid runtime errors.

• Object-Oriented Programming (OOP): Python fully supports OOP principles, allowing for the
creation of reusable and modular code through classes and objects. It also supports other
paradigms like procedural and functional programming.

• Large Standard Library and Ecosystem: Python comes with a comprehensive standard library
offering modules for various tasks, from web development to scientific
computing. Additionally, a vast ecosystem of third-party libraries further extends its
capabilities.

• Cross-Platform Compatibility: Python code can run on different operating systems


(Windows, macOS, Linux) without requiring modifications, promoting portability.

• Extensibility and Embeddability: Python can be extended with modules written in other
languages (like C/C++) to enhance performance or access specific functionalities. It can also
be embedded within other applications.

• Free and Open Source: Python is freely available for use and distribution, encouraging
community contributions and development.

• GUI Support: Python offers various toolkits for developing graphical user interfaces, such as
Tkinter, PyQt, and Kivy.

• Automatic Memory Management (Garbage Collection): Python handles memory


management automatically through garbage collection, relieving developers from manual
memory allocation and deallocation.

PYTHON IS A MULTI PARADIGM LANGUAGE:-

Python is a multi-paradigm programming language. This means it supports and allows for coding in
various programming paradigms, rather than strictly adhering to a single one.

The primary paradigms supported by Python include:

• Object-Oriented Programming (OOP): Python fully supports OOP concepts like classes,
objects, inheritance, and polymorphism.
• Procedural Programming: Python can be used to write code in a procedural style, organizing
code into functions and procedures.

• Functional Programming: Python incorporates features that facilitate functional


programming, such as lambda expressions, map(), filter(), and reduce().

DATA TYPE:-

Tuple : -A Tuple is a way to store multiple items in a single variable.

Syntax: Tuples are written with round brackets: ( )

Key Feature: They are Immutable. This is the most important concept to remember. Once you create
a tuple, you cannot change it. You cannot add, remove, or change items inside it.

When to use it: Use a tuple when you have data that should not change during the program
execution, like the coordinates of a location (x, y) or days of the week.

Example- my_tuple = (“apple”,”banana”,”cherry”)

Loop:- In Python, loops are used to repeatedly execute a block of code. The two main types of loops
are for loops and while loops.

While Loop :-The While Loop is a control flow statement. It allows code to be executed repeatedly
based on a boolean condition.

How it works: The loop keeps running as long as (while) a specific condition is True. Once the
condition becomes False, the loop stops.

Risk: If the condition never becomes False, you create an "infinite loop," and the program will
crash or freeze.

Example- count = 0
while count < 5:

Print(count)

For loop :- A For Loop is used for iterating over a sequence (that is, either a list, a tuple, a dictionary,
a set, or a string).

How it Works : The for loop goes through a container (like a list) one by one, temporarily assigning
the current value to a variable you choose.

Risk: Low risk of infinite loop

Example- fruits = ["apple", "banana", "cherry"]


for fruit in fruits:
print(fruit)
Feature for loop while loop

Purpose Iterating over sequences (lists, tuples, strings, Repeating a block of code as long as a
range objects) when the number of iterations specified condition remains true. Useful
is known or can be determined from the when the number of iterations is unknown
sequence. beforehand.

Control Flow Iterates through each item in a sequence. Continues execution based on a boolean
condition.

Initialization & Loop variable is implicitly initialized and Requires explicit initialization of control
Update updated by iterating through the sequence. variable(s) before the loop and explicit
updates within the loop body.

Termination Automatically terminates after iterating Terminates when the specified condition
through all items in the sequence. becomes false. Can lead to infinite loops if
the condition never becomes false.

Keywords for, in while

Typical Use Processing elements in a list, iterating a fixed Waiting for user input, repeating a task
Cases number of times using range(). until a specific event occurs, implementing
retry mechanisms.

Example python<br>for i in range(5):<br> print(i)<br> python<br>i = 0<br>while i < 5:<br>


print(i)<br> i += 1<br>

List:- A List is the most versatile way to store data in Python. Like a tuple, it stores multiple items in
one variable, but with a major difference.

Syntax: Lists are written with square brackets: [ ]

Key Feature: They are Mutable. You can add new items, delete items, or change an item at any time.

When to use it: Use a list for collections of data that might change, like a shopping list or a list of
users on a website.

EXAMPLE:- # An empty list


empty_list = []
# A list of numbers
numbers = [1, 2, 3, 4, 5]
# A list of strings
fruits = ["apple", "banana", "cherry"]
Feature List Tuple

Mutability Mutable (elements can be added, removed, or Immutable (elements cannot be


modified after creation) changed after creation)

Syntax Defined using square brackets [] Defined using parentheses ()

Performance Generally slower due to overhead for dynamic Generally faster due to static size and
resizing and modifications immutability

Memory Consumes more memory due to dynamic nature Consumes less memory due to static
Usage nature

Methods Extensive methods for modification Limited methods (e.g., count(), index())
(e.g., append(), remove(), sort())

Use Cases Suitable for dynamic collections where elements Suitable for fixed collections or data that
need frequent changes (e.g., user input, data that should not be modified (e.g.,
grows/shrinks) coordinates, record-like data)

Hashability Not hashable (cannot be used as dictionary keys or Hashable (can be used as dictionary keys
elements of a set) or elements of a set, provided their
elements are also hashable)

Safety More prone to accidental changes or errors due to Less prone to errors and safer for data
mutability integrity due to immutability

Python Packages:-Python provides robust support for working with various data formats and
network protocols through its standard library and external packages.

Data Formats:

• JSON (JavaScript Object Notation):

o The json module provides methods for encoding Python objects into JSON strings
and decoding JSON strings into Python objects.

o It is widely used for data interchange, especially in web applications and APIs.

• XML (Extensible Markup Language):


o The [Link] module (often aliased as ET) provides a lightweight and
efficient way to parse and generate XML data.
o Other modules like [Link] and [Link] offer alternative approaches for XML
processing.

• HTTP (Hypertext Transfer Protocol):

o [Link] (formerly httplib in Python 2): This module provides a low-level interface for
making HTTP requests. It allows for fine-grained control over headers, methods, and
request bodies.

• URL lib (URL handling library):

o The urllib package is a collection of modules for working with URLs.

o [Link] for parsing and manipulating URL components.

o [Link] for handling exceptions related to URL fetching.

o [Link] for parsing [Link] files.

• SMTP (Simple Mail Transfer Protocol):

o smtplib: This module provides an interface to the SMTP protocol, enabling


Python applications to send email messages.

You might also like