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

Introduction to Python Programming Basics

Uploaded by

amairakathuria10
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 views28 pages

Introduction to Python Programming Basics

Uploaded by

amairakathuria10
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

Dr Rishi Rajan Sahay


SSCBS
Four main
Analytics types of
analytics:

Descriptive Diagnostic Predictive Prescriptive


Analytics Analytics Analytics Analytics
Getting
started with
Python…
Python

Python was created by Guido van Rossum, and


first released on February 20, 1991. While you
may know the python as a large snake, the name
of the Python programming language comes
from an old BBC television comedy sketch series
called Monty Python's Flying Circus.
Python Why Learn Python?
•Easy to learn: Clean and readable syntax, close
Python is an interpreted,
to English.
high-level, general purpose
•Versatile: Used in web development,
programming language
automation, data science, machine learning,
(Downey, 2012). finance, etc.
•Strong Community & Libraries: Huge
One of the key design
ecosystem (e.g., NumPy, Pandas, Matplotlib,
philosophy of Python is code
scikit-learn).
readability. Ease of use and
•High Demand: Widely used in industry and
high productivity have made
academia.
Python very popular.
Python is a programming language that can be used to build various types of
applications

• GUI Development
• Web Development
• Game Development
• Scientific Development
• Data Analytics
• Data Science
• Visualization
• Machine Learning
• Internet of Things (IoT)
Popularity of different programming languages
Tiobe index 2025:
1. Python
2. C++
3. C
4. Java
5. Java script

Statista Report 2025


(Top 3 languages
demanded by recruiters)
1. Python
2. Java script
3. Java
• Opening a new notebook in ‘Jupyter’ and naming it

• Different data types in Python


Operators
Operators in Python are used to manipulate data and perform calculations.
Different types of operators in Python:

Arithmetic Operators: Assignment Operators:

+ : Addition = : Assigns a value to a variable


- : Subtraction += : Adds and assigns
* : Multiplication -= : Subtracts and assigns
/ : Division (floating-point) *= : Multiplies and assigns
// : Division (floor division, returns integer result) /= : Divides and assigns
% : Modulus (remainder) //= : Floor divides and assigns
** : Exponentiation %= : Modulus and assigns
**= : Exponentiation and assigns
Little more on assignment operators..

x=7 # assigns a value 7 to the variable x


x+= 3 # Equivalent to x = x + 3
x=
Relational or Comparison Operators Logical Operators:
These operators are used to compare values Logical operators are used to perform
and determine the relationship between logical operations on boolean values
them. They return Boolean values (either (True or False). They are also used in
True or False) control structures (if statements and
loops) to make decisions based on
== : Equal to multiple conditions
!= : Not equal to
< : Less than and : Logical AND
> : Greater than or : Logical OR
<= : Less than or equal to not : Logical NOT
>= : Greater than or equal to
x = True # not x will return False
y = False

# The following will return False, since both x and y are not True

x and y

# The following will return True, since x is True and y is not True (False)

x and not y
• Python is case sensitive
• Python provides a big set of built-in
function
a) Print() function – to print something to the
screen
b) Input() function – returns strings type of
data only
c) Int() function – convert string to integer
value
d) Float() function – converts into floating
value
Data Structure

In Python, data structures are ways


Key Data Types of organizing and storing data so
that it can be accessed and worked
Numeric: int, float, complex with efficiently. They are
fundamental building blocks for
Text: str writing programs

Boolean: True, False Different data structure in python


are:

List, tuple, dictionary, and set


List

A list in Python is an ordered collection of items. It's one of the most versatile
data types and can hold elements of different data types. Lists are mutable,
meaning it can be changed after creation.

A list is defined by using square brackets [ ] and separating the elements with
commas.

For ex: age=[18,20,19,22]


List
Accessing elements
First element: age[0]
Last element: age[-1]
Slicing a list: First three elements: age[0:3]
Modifying elements: age[1] = 25
Adding elements: [Link](20) # Add to the end

[Link](2, 24) # Insert at a specific index

Removing elements
del age[2] # removes third element
[Link](20) # Remove by value
[Link]() # Remove the last element

# List length
print("Length of the list:", len(age))
Tuple

A tuple in Python is similar to a list, but it is immutable, meaning you cannot


change its elements after creation. Tuples are defined using parentheses ()
and separating the elements with commas. They are often used for storing
related pieces of data that should not be modified.

For ex: Age =(20, 24, 22, 19, 25)


Tuple
Accessing elements
First element: Age[0]
Last element: Age[-1]
Slicing a list: First three elements: Age[0:3]
18odifying elements: Age[1] = 5 # It will show error
Adding elements: [Link](20) # show error

# Tuple length
print("Length of the tuple:", len(Age))
Set

A set in Python is an unordered collection of unique elements. This


means that a set cannot have duplicate values. Sets are mutable. Sets
are useful for operations like checking for membership, removing
duplicates, and performing mathematical set operations (union,
intersection, difference). You define a set using curly braces {} or the
set() constructor.
# Creating a set
marks = {10, 22, 23, 14, 25, 25, 14, 18} # Duplicates are automatically removed

print(“My set:", marks)

# Adding elements
marks .add(16)

print("Set after adding 16:", marks)

# Removing elements
[Link](14) # Remove by value (raises error if element not found)

[Link](8) # Remove by value (does nothing if element not found)

Checking for membership


print("Is 15 in the set?", 15 in marks)
print("Is 10 in the set?", 10 in marks)
# Set length
len(marks))

# Iterating through a set (note: order is not guaranteed)

print("Iterating through the set:")


for item in my_set: print(item)

# Set operations
set1 = {1, 2, 3, 4}, set2 = {3, 4, 5, 6}
union_set = [Link](set2)

print("Union of set1 and set2:", union_set)

# intersection_set = [Link](set2)
print("Intersection of set1 and set2:", intersection_set)
# Difference
difference = [Link](set2)

print("Difference of set1 and set2 (set1 - set2):",


[Link](set2)

Or set1 – set2
Dictionary

A dictionary in Python is an unordered, mutable collection of items where


each item is stored as a key-value pair. Dictionaries are optimized for
retrieving values when the key is known. Keys must be unique and
immutable (like strings, numbers, or tuples), while values can be of any data
type and can be duplicated. You define a dictionary using curly braces {} with
key-value pairs separated by colons (:) and the pairs separated by commas
(,).
# Creating a dictionary
dict = {"BMS": 300, "BBA": 150, "BSC": 70}
print("my dictionary:", dict)

# Accessing elements
print("Value for 'BBA':", dict["BBA"])

# Modifying elements
dict[‘BSC’] = 60
print("Dictionary after modifying:", dict)

# Adding new elements


dict[“PG"] = 50
print("Dictionary after adding :", dict)

# Removing elements
del dict[“BSC"] # Remove by key
print("Dictionary after removing ‘BSC':", dict)
# Dictionary length: len(dict))

You might also like