Python Notes
Python Notes
What is Python?
Features of Python
Applications Of Python
Python Installation
First Python Program
By @Curious_.programmer
CodeWithCurious.com
Chapter 1: Introduction
to Python
Made By:
For Windows:
Visit the official Python website at
www.python.org/downloads/
Developer Tools.
CodeWithCurious Store
Today’s Topics:
Modules in Python
Types of Modules
Comments in Python
PIP
By @Curious_.programmer
CodeWithCurious.com
Chapter 2: Modules,
Comment & Pip
Made By:
Modules
Built-in Modules:
Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
Want Complete PDF? Download From Our Telegram
These are modules that come pre-installed with Python.
Channel @Curious_Coder
Types of Comments
They start with a hash symbol (#) and continue until the
end of the line.
2. Multi-line comments:
Multi-line comments, also known as block comments, allow
you to add comments that span multiple lines.
CodeWithCurious Store
Today’s Topics:
Variables
Data Types
Keywords
By @Curious_.programmer
CodeWithCurious.com
3. Variables, Data Types
& Keywords
Made By:
MyClass
3. Boolean:
Boolean (bool): Booleans represent truth values, either True
or False. They are used for logical operations and
conditions. For example, is_valid = True.
4. Set:
Sets (set): Sets are unordered collections of unique
elements enclosed in curly braces. They are useful for
mathematical operations such as union, intersection,
and difference. For example, fruits = {'apple', 'banana',
'orange'}.
5. Sequence Type:
Sequences represent a collection of elements and include
data types like strings, lists, and tuples. Strings are used to
store textual data, while lists and tuples are used to store
Copyrighted By : Instagram: Curious_.Programmer
ordered collections of items. CodeWithCurious.com
Want Complete PDF? Download From Our Telegram
Channel @Curious_Coder
CodeWithCurious Store
Will Post Tomorrow Follow For More
Todays Topic:
Arithmetic operators
Comparison operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
Arithmetic Operators
By @Curious_.programmer
4. Operators in
Python
Made By:
Arithmetic operators
Comparison operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
Arithmetic Operators
Arithmetic Operators:
Arithmetic operators in Python are used to perform
mathematical calculations on numeric values. The basic
arithmetic operators include:
Addition (+): Adds two operands together. For example, if
we have a = 10 and b = 10, then a + b equals 20.
Comparison Operators:
Comparison operators in Python are used to compare two
values and return a Boolean value (True or False) based on
the comparison. Common comparison operators include:
Equal to (==): Checks if two operands are equal.
Less than (<): Checks if the left operand is less than the
right operand.
Assignment Operators:
Assignment operators are used to assign values to variables.
They include:
Equal to (=): Assigns the value on the right to the variable
on the left.
Logical Operators:
Logical operators in Python are used to perform logical
operations on Boolean values. The main logical operators
are:
Logical AND (and): Returns True if both operands are
True, otherwise False.
Logical OR (or): Returns True if at least one of the
operands is True, otherwise False.
Bitwise Operators:
Bitwise operators perform operations on individual bits of
binary numbers. Some common bitwise operators in Python
are:
Bitwise AND (&): Performs a bitwise AND operation on the
binary representations of the operands.
Right shift (>>): Shifts the bits of the left operand to the
right by the number of positions specified by the right
operand.
Right shift (>>): Shifts the bits of the left operand to the
right by the number of positions specified by the right
operand.
Membership Operators:
Membership operators are used to test whether a value is a
member of a sequence (e.g., string, list, tuple). They include:
In: Returns True if the value is found in the sequence.
Identity Operators:
Identity operators are used to compare the identity of two
objects. They include:
Is: Returns True if both operands refer to the same object.
CodeWithCurious Store
Will Post Follow For More
Today’s Topics:
If statements?
Else and Elif statements
Nested If statement
The While Loop
The For Loop
Loop control statements
Use range() in For Loop
By @Curious_.programmer
5. Control Flow
Made By:
Control Flow
Control flow directs program execution through structures
like loops, conditionals, and functions, determining the order
and path of operations. Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
If statements
Want Complete PDF? Download From Our Telegram
Channel @Curious_Coder
example:
Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
Want Complete PDF? Download From Our Telegram
Channel @Curious_Coder
Nested if Statement
If the weather isn’t sunny, you skip the nested checks and
go straight to an alternative action, like staying indoors.
example:
Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
Want Complete PDF? Download From Our Telegram
Channel @Curious_Coder
The While Loop
A `while` loop in Python repeatedly executes a block of code
as long as a specified condition is true.
For example
A `while` loop can keep counting up as long as the count is
below a certain number. It's useful for scenarios where you
Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
For example
It can go through a list of numbers, processing each one in
turn. It's ideal for repetitive tasks like iterating over data
collections.
example:
Copyrighted By : Instagram: Curious_.Programmer
CodeWithCurious.com
Want Complete PDF? Download From Our Telegram
Channel @Curious_Coder
example:
example:
Using Range() in For Loop
example:
By @Curious_.programmer
Lists and Tuples
Lists and tuples in Python both store collections of items.
Lists are mutable, allowing changes like adding or removing
elements, and use square brackets (`[ ]`).
Key Features:
1. append()
Adds a single element to the end of the list.
Syntax: list.append(element)
2. extend()
Extends the list by appending elements from an iterable
(like another list).
Syntax: list.extend(iterable)
3. insert()
Inserts an element at a specified position in the list.
Syntax: list.insert(index, element)
4. remove()
Removes the first occurrence of a specified element from
the list.
Syntax: list.remove(element)
5.pop()
Removes and returns the element at a specified position
(index). If no index is specified, it removes and returns
the last element.
Syntax: list.pop(index)
Indexing
Key Points:
1.Positive Indexing:
3. Indexing in Strings:
4. Out-of-Range Index:
Slicing
List Comprehension
Syntax:
expression: The value or operation applied to each item.
item: The variable representing the current element in the
iteration.
iterable: The collection (like a list, tuple, or range) that you
are iterating over.
condition: (Optional) A filter that decides whether the
expression should be applied to the current item.
Tuple Unpacking:
Tuple unpacking is the reverse process, where the values in a
tuple are extracted and assigned to individual variables.
CodeWithCurious Store
7. Dictionaries and
sets
Made By:
Dictionaries
Dictionaries Methods
1. dict.get()
The get() method retrieves the value for a specified key. If the
key is not found, it returns None or a specified default value.
examples:
2. dict.keys()
The keys() method returns a view object that displays a list
of all the keys in the dictionary.
m.
examples:
3. dict.values()
The values() method returns a view object that displays a
list of all the values in the dictionary.
examples:
4. dict.items()
The items() method returns a view object that displays a list
of tuples, where each tuple is a key-value pair.
examples:
5. dict.update()
The update() method updates the dictionary with elements
from another dictionary or iterable of key-value pairs. If a
key already exists, its value will be updated.
examples:
6. dict.pop()
The pop() method removes a specified key and returns its
corresponding value. If the key is not found, it raises a
KeyError, unless a default value is provided.
examples:
7. dict.popitem()
The popitem() method removes and returns a (key, value)
pair as a tuple.
examples:
8. dict.clear()
The clear() method removes all items from the dictionary,
leaving it empty.
examples:
9. dict.copy()
The copy() method returns a shallow copy of the dictionary.
examples: