0% found this document useful (0 votes)
5 views

Notes-1

The document provides an introduction to Python programming, highlighting its origins, features, and basic concepts. It covers topics such as variables, data types, operators, and built-in functions, emphasizing Python's simplicity and versatility. Key milestones in Python's development and its applications in various fields like AI and web development are also mentioned.

Uploaded by

Shivam Singh
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)
5 views

Notes-1

The document provides an introduction to Python programming, highlighting its origins, features, and basic concepts. It covers topics such as variables, data types, operators, and built-in functions, emphasizing Python's simplicity and versatility. Key milestones in Python's development and its applications in various fields like AI and web development are also mentioned.

Uploaded by

Shivam Singh
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
You are on page 1/ 5

Python Programming - Unit I Notes

Prepared by: Dr. Pangambam Sendash Singh


February 12, 2025

h
ng
1 Introduction to Python

Si
Python is a high-level, interpreted programming language known for its simplicity and
readability.

h
1.1 Origins of Python

as
Python was created by Guido van Rossum in 1989 and officially released in 1991. It
was developed as a successor to the ABC programming language. The name Python was
nd
inspired by the British comedy show Monty Python’s Flying Circus.
Key Milestones:

ˆ 1991: Python 1.0 released


Se

ˆ 2000: Python 2.0 released (introduced list comprehensions, garbage collection)

ˆ 2008: Python 3.0 released (major improvements, removed backward compatibility)


m

ˆ Python 3.13.2: Released on February 4, 2025


ba

1.2 Features of Python


m

ˆ Simple and easy to learn syntax

ˆ Interpreted (no compilation required)


ga

ˆ Dynamically typed (no need to declare variable types)


n

ˆ Object-oriented and functional programming support


Pa

ˆ Cross-platform compatibility

ˆ Extensive libraries (NumPy, Pandas, TensorFlow, Django, etc.)

ˆ Automatic garbage collection

ˆ Embeddable and extensible with C/C++

Widely used in AI, ML, Web Development, Automation, and Data Science

1
2 Variables and Assignment
Variables store values in memory. Variables in Python are dynamically typed and do not
require explicit declaration and are case-sensitive.
Example:
1 x = 10 # Integer
2 y = 3.14 # Float
3 name = " John " # String
flag = True # Boolean

h
4

Multiple Assignments:

ng
1 a , b , c = 10 , 20 , " Hello "
2 x = y = z = 50 # Assign the same value to multiple variables

Si
Swapping Variables:
1 a , b = 5 , 10
2 a , b = b , a # Swap values without a temporary variable

h
3 print (a , b ) # Output : 10 5

3 Python Basics
as
nd
Python script files have a .py extension. Execution is done via the Python interpreter:
Se
1 python my_script . py

3.1 Syntax and Comments


m

Python syntax is simple and uses indentation to define blocks of code. Python uses
indentation (instead of { } like C/C++). Comments are written using # for single-line
ba

and ‘‘‘ ’’’ or ‘‘ ‘‘ ‘‘ ’’ ’’ ’’ for multi-line comments. Python statements are


executed sequentially, and indentation is crucial for defining blocks. Python statements
are executed sequentially, and indentation is crucial for defining blocks.
m

Example:
1 # This is a single - line comment
ga

2
3 """
4 This is a
n

5 multi - line comment


6 """
Pa

7
8 print ( " Hello , World ! " ) # Output : Hello , World !

ˆ Statements: Python instructions executed at runtime.

ˆ Syntax: Rules for structuring code.

ˆ Python Objects: Everything in Python is an object (numbers, strings, lists,


functions, etc.). Objects have attributes and methods.

2
3.2 Identifiers
Identifiers: Names given to variables, functions, classes, etc.

Identifier Naming Rules:

ˆ Must begin with a letter (A-Z, a-z) or underscore ( )

ˆ Cannot start with a digit (e.g., 1var is invalid)

h
ˆ Cannot contain special characters (e.g., Roll#, US$ are invalid)

ng
ˆ Cannot use Python keywords (e.g., def, class, return)

ˆ Case-sensitive (Var ̸= var)

Si
4 Standard Types and Other Built-in Types

h
Python has various data types:

4.1 Primitive Data Types:

as
nd
ˆ Numeric Types: int, float, complex

ˆ Boolean Type: bool (True, False)


Se

ˆ String Type: str

4.2 Collection Data Types:


m

ˆ List: Ordered, mutable collection ‘[ ]’

ˆ Tuple: Ordered, immutable collection ‘( )’


ba

ˆ Set: Unordered, unique values ‘{ }’


m

ˆ Dictionary: Key-value pairs ‘{ }’

Mutable/Immutable Types:
ga

ˆ Mutable Types: Can be modified (e.g., Lists, Dictionaries).


n

ˆ Immutable Types: Cannot be changed (e.g., Strings, Tuples).


Pa

Example:
1 lst = [1 , 2 , 3 , " Python " ] # List
2 tpl = (10 , 20 , 30) # Tuple
3 st = {1 , 2 , 3 , 3} # Set ( removes duplicates )
4 dct = { " name " : " John " , " age " : 25} # Dictionary

5 Operators in Python
Operators are special symbols used to perform operations on variables and values.

3
5.1 Arithmetic Operators
ˆ Addition: + Example: 5 + 3 ⇒ 8

ˆ Subtraction: - Example: 10 - 4 ⇒ 6

ˆ Multiplication: * Example: 6 * 7 ⇒ 42

ˆ Division: / Example: 15 / 2 ⇒ 7.5

h
ˆ Floor Division: // Example: 15 // 2 ⇒ 7

ng
ˆ Modulus: % Example: 10 % 3 ⇒ 1

ˆ Exponentiation: ** Example: 2 ** 3 ⇒ 8

Si
5.2 Relational Operators
ˆ Equal to: ==

h
Example: 5 == 5 ⇒ True

ˆ Not equal to: !=

as
Example: 5 != 3 ⇒ True

ˆ Greater than: > Example: 10 > 5 ⇒ True


nd
ˆ Less than: < Example: 3 < 7 ⇒ True

ˆ Greater than or equal to: >= Example: 8 >= 8 ⇒ True


Se

ˆ Less than or equal to: <= Example: 4 <= 9 ⇒ True

5.3 Bitwise Operators


m

ˆ AND: & Example: 5 & 3 ⇒ 1


ba

ˆ OR: | Example: 5 | 3 ⇒ 7

ˆ XOR: ∧ Example: 5 ∧ 3 ⇒ 6
m

ˆ NOT: ∼ Example: ∼5 ⇒ -6
ga

ˆ Left Shift: << Example: 5 << 1 ⇒ 10

ˆ Right Shift: >> Example: 5 >> 1 ⇒ 2


n
Pa

5.4 Other Operators


ˆ Assignment Operators: =, +=, -=, *=, /=, //=, %=, **= Example: x += 5 (if
x = 2, then x becomes 7)

ˆ Logical Operators: and, or, not Example: (5 > 3) and (10 > 7) ⇒ True

ˆ Membership Operators: in, not in Example: 5 in [1, 2, 3, 4, 5] ⇒ True

ˆ Identity Operators: is, is not Example: x is y (returns True if x and y reference


the same object)

4
6 Built-in Functions
Python provides many built-in functions:

Function Purpose
type(x) Returns type of x
len(x) Returns length of x
max(x), min(x) Find maximum/minimum value
Sorts a sequence

h
sorted(x)

ng
Example:
1 numbers = [4 , 7 , 1 , 9]
2 print ( max ( numbers ) ) # Output : 9

Si
3 print ( min ( numbers ) ) # Output : 1
4 print ( sorted ( numbers ) ) # Output : [1 , 4 , 7 , 9]

h
6.1 Standard Type Built-in Functions

as
Function Purpose
type(x) Returns type of x
nd
len(x) Returns length of x
str(x), int(x), float(x) Type conversion
max(x), min(x) Find maximum/minimum value
Se
sorted(x) Sorts a sequence
m
ba
m
n ga
Pa

You might also like