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

Python Digital Notes

The document provides an overview of Python, a high-level programming language known for its readability and ease of use. It covers essential concepts such as tokens, keywords, identifiers, literals, operators, control statements, data types, and data structures like lists and dictionaries. Additionally, it discusses debugging techniques and type conversion in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views15 pages

Python Digital Notes

The document provides an overview of Python, a high-level programming language known for its readability and ease of use. It covers essential concepts such as tokens, keywords, identifiers, literals, operators, control statements, data types, and data structures like lists and dictionaries. Additionally, it discusses debugging techniques and type conversion in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

INFORMATION PRACTICES

(IP-065)
SESSION: 2025-26

DIGITAL NOTES

UNIT- 2
(PYTHON)

SUBMITTED BY: SUBMITTED TO:


YASH SOLANKI MANISH AGARWAL

PYTHON
 Python is a high level programing language for programmer/software
developer as well as for begginers.
 Python was developed by Sir Guido Van Rossum in the year 1991
 Python is also known for readability and for easy usage, making it popular
among all types of experienced software developer and also popular for
beginners.
Features Of Python;-
1. Used for software development
2. Library based language
3. Free & Open source language
4. Free & User friendly language
5. Easy & Less code programming language

TOKENS

 In Python, Tokens are the smallest individual units of a program that are
meaningful to the interpreter.
 Tokens are the building block of language syntax and python interpreter
breaks down the source code into these tokens during the analysis phase
before processing it.

Types Of Tokens;-
1. Keywords
2. Identifiers
3. Operators
4. Literals
5. Punctuators

Keywords
 Keywords are reserved words that have predefined meanings and purposes
within the language.
Identifier

 An identifier is a name, like a variable, function, or class name, used to


uniquely identify a component within a computer program or system.
 The python identifier follows some specific rules that are;-

1. An Identifier starts with letter A-Z or a-z or underscore(_). Followed by 0 or


more letters like 0-9.
2. Python does not allow special character.
3. Identifier must not be a keyword of python.
4. Python is a case sensitive programming language.

Some Valid Identifier


 My book
 File 1239
 p39yt
 time_9
 _beautiful
Some Invalid Identifier
 7th
 Global
 Is
 False
 [Link]
 Date-sheet

Literals
 In Python, a literal is a notation that represents a fixed value directly in the
source code.
 Literals can be numbers(Integers,Float), Boolean(True,False), string or other
special values like none.

Escape Sequence

Operators
 Operators in Python are special symbols that perform operations on values
and variables.

Types of Operators;-
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Membership Operators
6. Bitwise Operators
7. Identity Operators

Punctuators
 Punctuators in Python are special symbols used to structure and organize
code, providing grammatical and syntactic meaning.
 Following are some python punctuators;-

INPUT AND OUTPUT STATEMENT


Input Statement
 Python uses Input functions to take input from keyboard. This function takes
value from keyboard and returns as a string.

Output Statement
 The print () function is used to display output to the console.

DEBUGGING
 It is the process of finding and fixing errors (or "bugs") in your code that
prevent it from working as intended.
 Pdb is the Python Debugger, an interactive source code debugger included in
Python's standard library.
Pdb Supports
1. Setting break points
2. Stepping through code
3. Source code listing
4. Viewing stack traces

DATATYPE IN PYTHON

 A data type is a classification that specifies the kind of value a variable can
hold and determines the operations that can be performed on that data.

Examples of Datatype
1. Numeric
2. Sequence
3. Mapping type
4. Boolean
5. Set type
6. Binary type
DATATYPE CONVERSION
OR
TYPE CASTING

 Type conversion in Python, also known as typecasting, is the process of


changing the data type of a value from one type to another.
 Python supports two main type of conversion;-
1. Implicit Type Conversion
2. Explicit Type Conversion

Implicit Type Conversion


 Implicit type conversion in Python, also known as type coercion, is the
automatic conversion of one data type to another by the Python interpreter
during an operation. This conversion occurs without explicit instructions from
the programmer.

Explicit Type Conversion


 Explicit type conversion in Python, also known as type casting, involves
manually changing the data type of an object using built-in functions. This is
done when Python's automatic (implicit) type conversion is not sufficient or
when precise control over data types is required.

Mutable datatype
 In Python, mutable data types are those whose values can be changed or
modified after they are created. This means that you can alter their content or
structure in place without creating a new object in memory.

Immutable datatype
 In Python, an immutable data type refers to a type of object whose value
cannot be changed after it is created. Once an object of an immutable type is
assigned a value, its state remains constant throughout its lifetime.
CONTROL STATEMENTS

 Control statements in Python are programming constructs that dictate the flow
of execution within a program.

Types of Control Statements


1. Decision-making statement
2. Iteration statement
3. Jump statement

Decision making statement


 In Python, decision-making statements, also known as conditional statements,
are used to control the flow of program execution based on whether certain
conditions are met.

Types of Decision making statements


1. If statement;- In Python, if statements are fundamental control flow
statements that allow a program to make decisions and execute specific
blocks of code based on whether a given condition is true or false.
2. If-else statement;- In Python, the if-else statement is a fundamental control
flow structure used for decision-making. It allows a program to execute
different blocks of code based on whether a specified condition evaluates
to True or False.
3. Nested if-else statement;- Nested if-else statements in Python refer to the
practice of placing an if statement (with or without its
corresponding else or elif blocks) inside another if or else block.

Iteration statement
 Iterative statements in Python, also known as loops, are control flow
structures that allow a block of code to be executed repeatedly.

Types of Iteration statement;-


1. While loop;- In Python, a while loop is a control flow statement that
repeatedly executes a block of code as long as a specified condition remains
true.
2. For loop;- A for loop in Python is a control flow statement used for iterating
over a sequence (such as a list, tuple, string, or range) or other iterable
objects.
3. Nested for loop;- A nested for loop in Python refers to a for loop placed
inside another for loop.
Example(while loop)
x=1
while(x<=7)
print(x)
x=x+1
output:
1
2
3
4
5
6
7

Example(for loop)
For I range (2,6)
print(i)
output;
2
3
4
5

Example(nested for loop)


for (i) range (1,3):
for (j) range (1,11):
k=i*j
print(k, end=’’)
print(k)
output
1 2 3 4 5 6 7 8 9 10 ; 2 4 6 8 10 12 14 16 18 20
JUMP STATEMENT

 Jump statements in Python are keywords that alter the normal, sequential
flow of program execution.

Types of Jump Statement


Break;- The break statement in Python is a control flow statement used to terminate
the execution of a loop.

Example;- for val in range “string”:


If val==”i”:
break
print(val)
output:
s
t
r

Continuous;- In Python, the continue statement is a loop control statement used to


skip the current iteration of a loop and proceed to the next iteration.

Example;- for(val) in=”init”:


If(val)==”i”
continue
print(val)
print(the end)
output:
n
t
“the end”
Pass;- The pass statement in Python is a null operation; it does nothing when
executed.

Example;-
for(i) in “initial”:
if i==’i’:
pass
else
print(i)
output:
n
t
a
l

LISTS
 In Python, a list is a fundamental, built-in data structure used to store an
ordered collection of items.

Creating a list
 Lists are enclosed in squared brackets [] and each item is separated by
comma (,).

Initializing a List

 Passing value in the list, which declaring list is initializing of a list.

For example
list 1=[23,11,45,31,29]
list 2=[‘Science’,’Maths’,2021,2025]
list 3=[‘a’,’b’,’c’,’d’]
Access Items from a List
list=[25,7,9,36,122]
print(list[0])
print(list[1])
print(list[3])
output:
25
7
36

Iterating items through a list


 List elements can be accessed using loop statement.

For example
list=[4,6,7]
for I in range(0,len(list))
print(list[i])
output:
[‘I’,’N’,’D’]
[‘I’,’A’]
[‘I’,’N’,’D’,’I’,’A’]
Add items in a list
list=[1,2]
print ('list before adding’,list]
[Link](5)
print('list after adding an item’, list)
output:
(list before adding, [1,2])
(list before adding an item,[1,2,5])

Add two list


We can add two or more list with each other.
list 1=[1,2]
list 2=[3,4]
list 3=list 1+list 2
print list(3)
output:
[1,2,3,4]

Delete an item from a list


We can delete any item from a list.
list=[1,2,3]
print(list)
del list[2]
print(list)
output:
[1,2,3]
[1,3]
DICTIONARY

 In Python, a dictionary is a built-in data structure used to store data values in


key-value pairs.

Creating a Dictionary
 Dictionary is enclosed with curly braces {} and each item is separated from
other item by a comma (,).
 Within each item, the key and value are separated by a colon(:).
 Passing the value in dictionary at declaration is dictionary initialization.

Example
dict={‘Subject’:’IP’,’Class’:11}

Accessing items through a dictionary


dict={‘Subject’:’IP’,’Class’:11}
print(dict)
print(“subject:”,dict[‘subject’])
print(“class:”,dict[‘class’]

Iteration through a dictionary


dict={‘Subject’:’IP’,’Class’:11}
for i in dict:
print(dict(i))
output:
IP
11

Updating or Manipulating dictionary


dict={‘Subject’:’IP’,’Class’:11}
dict[‘subject’]=’cs’
print(dict)
output:
{‘subject’=cs,’Class’=11}

You might also like