SlideShare a Scribd company logo
Computer Science with Python
Class: XII
Unit I: Computational Thinking and Programming -2
Chapter 1: Review of Python basics I (Revision Tour Class XI)
Mr. Vikram Singh Slathia
PGT Computer Science
Python
• In class XI we have learned about Python. In this class we will
learn Python with some new techniques.
• Python was created by Guido van Rossum. Python got its name
from a BBC comedy series – “Monty Python’s Flying Circus”.
• Python is based on two programming languages:
a. ABC Language b. Module 3
• We know that Python is a powerful and high level language and it
is an interpreted language.
• Python gives us two modes of working-
 Interactive mode
It allows us to interact with OS. It executes the code by typing in
Python Shell Script mode
In this we type python program in a file and then use interpreter
to executes the content of the file
Tokens
• Token is the smallest unit of any programming language. It is also
known as Lexical Unit. Types of token are-
i. Keywords
ii. Identifiers (Names)
iii. Literals
iv. Operators
v. Punctuators
i. Keywords
Keywords are those words which
provides a special meaning to
interpreter.
These are reserved for specific
functioning. These can not be
used as identifiers, variable name
or any other purpose.
Available keywords in Python are-
ii. Identifiers
• These are building blocks of a program and are used to give
names to different parts/blocks of a program like - variable,
objects, classes, functions.
• An identifier may be a combination of letters and numbers. An
identifier must begin with an alphabet or an underscore( _ ) not
with any number.
• Python is case sensitive. Uppercase characters are distinct from
lowercase characters (P and p are different for interpreter).
• Keywords can not be used as an identifier.
• Space and special symbols are not permitted in an identifier name
except an underscore( _ ) sign.
• Some valid identifiers are –
• Myfile, Date9_7_17, Z2T0Z9, _DS, _CHK FILE13.
• Some invalid identifiers are –
• DATA-REC, 29COLOR, break, My.File.
iv. Literals / Values
• Literals are often called Constant Values.
• Python permits following types of literals -
◦ String literals – “Pankaj”
◦ Numeric literals – 10, 13.5, 3+5j
◦ Boolean literals – True or False
◦ Special Literal None
◦ Literal collections
String Literals
String Literal is a sequence of characters that can be a combination
of letters, numbers and special symbols, enclosed in quotation
marks, single, double or triple(“ “ or ‘ ‘ or “’ ‘”).
In python, string is of 2 types-
• Single line string
Text = “Hello World” or Text = ‘Hello World’
• Multi line string
Text = ‘hello or Text = ‘’’hello
world’ word ‘’’
Numeric Literals
 Numeric values can be of three types -
• int (signed integers)
• Decimal Integer Literals – 10, 17, 210 etc.
• Octal Integer Literals - 0o17, 0o217 etc.
• Hexadecimal Integer Literals – 0x14, 0xABD etc.
 float ( floating point real value)
• Fractional Form – 2.0, 17.5 -13.5, -.00015 etc.
• Exponent Form - -1.7E+8, .25E-4 etc.
 complex (complex numbers)
• 3+5i etc.
Boolean Literals
It can contain either of only two values – True or False
Special Literals
None, which means nothing (no value).
v. Operators
An Operator is a symbol that trigger some action when applied to
identifier(s)/ operand (s). Therefore, an operator requires operand(s)
to compute upon. example :
c = a + b
Here, a, b, c are operands and operators are = and + which are
performing differently.
vi. Punctuators
In Python, punctuators are used to construct the program and to
make balance between instructions and statements.
Punctuators have their own syntactic and semantic significance.
• Python has following Punctuators -
‘, ”, #, , (, ), [, ], {, }, @. ,, :, .. `, =
CORE
DATA
TYPE
Numbe
rs
Non
e
Sequenc
es
Mappin
gs
Integ
er
Floatin
g
Point
Compl
ex
Strin
g
Tupl
e
Lis
t
Dictiona
ry
Boole
an
DATA TYPES
Variables and Values
An important fact to know is-
◦ In Python, values are actually objects.
◦ And their variable names are actually their reference names.
Suppose we assign 12 to a variable
A = 12
Here, value 12 is an object and A is its reference name.
Mutable and Immutable Types
Following data types comes under mutable and immutable types-
• Mutable (Changeable)
 lists, dictionaries and sets.
• Immutable (Non-Changeable)
 integers, floats, Booleans, strings and tuples.
Operators
• The symbols that shows a special behavior or action when applied to
operands are called operators. For ex- + , - , > , < etc.
• Python supports following operators-
i. Arithmetic Operator
ii. Relation Operator
iii. Identity Operators
iv. Logical Operators
v. Bitwise Operators
vi. Membership Operators
Operator Associativity
In Python, if an expression or statement consists of multiple or
more than one operator then operator associativity will be
followed from left-to- right.
In above given expression, first 7*8 will be calculated as 56, then 56
will be divided by 5 and will result into 11.2, then 11.2 again
divided by 2 and will result into 5.0.
Only in case of **, associativity will be followed from right-to-left.
Above given example will be calculated as 3**(3**2).
Type Casting
As we know, in Python, an expression may be consists of
mixed datatypes.
In such cases, python changes data types of operands
internally. This process of internal data type conversion is
called implicit type conversion.
➢ One other option is explicit type conversion which is like-
<datatype> (identifier)
For ex-
a=“4”
b=int(a)
Another ex-
If a=5 and b=10.5 then we can convert a to float.
Like d=float(a)
In python, following are the data conversion functions-
a. int ( ) b. float( ) c. complex( ) d. str( ) e. bool( )
Taking Input in Python
• In Python, input () function is used to take input which takes input
in the form of string. Then it will be type casted as per
requirement. For ex- to calculate volume of a cylinder, program will
be as-
Its output will be as-
Types of statements in Python
In Python, statements are of three types:
» Empty Statements
• pass
» Simple Statements (Single Statement)
• name=input (“Enter your Name “)
• print(name) etc.
» Compound Statements
<Compound Statement Header>:
<Indented Body containing multiple simple
statements /compound statements >
• Header line starts with the keyword and ends at colon (:)
• The body consists of more than one simple Python
statements or compound statements.
Statement Flow Control
In a program, statements executes in sequential manner or
in selective manner or in iterative manner.
Sequential Selective Iterative
If conditional come in multiple forms:
• if Condition
• if-else condition
• if-elif conditional
• Nested if statement
if Statement
An if statement tests a particular condition;
If the condition evaluates to true, a course of action is
followed. If the condition is false, it does nothing.
Syntax:
if <condition>:
statement(s)
if-else Statements
If the condition evaluates to true, it carries out
statement indented below if and in case condition
evaluates to false, it carries out statements indented
below else.
Syntax:
if <condition>:
statement(s) when if condition is true
else:
statement(s) when else case is true dition is false
if-elif conditional
if statements are executed from the top down. As soon as one of the
conditions controlling the if is true, the statement associated with
that if is executed, and the rest of the ladder is bypassed. If none of
the conditions is true, then the final else statement will be executed.
The elif keyword is pythons way of saying "if the previous
conditions were not true, then try this condition".
Syntax:
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else
Flow Chart
Example:
num = 3.4
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Nested If -else
A nested if is an if statement that is the target of another if
statement. Nested if statements means an if statement inside
another if statement.
Syntax:
if (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
# if Block is end here
# if Block is end here
Example:
i = 10
if (i == 10):
# First if statement
if (i < 15):
print ("i is smaller than 15")
# Nested - if statement, Will only be executed if statement above it is true
if (i < 12):
print ("i is smaller than 12 too")
else:
print ("i is greater than 15")i = 10
if (i == 10):
# First if statement
if (i < 15):
print ("i is smaller than 15")
# Nested - if statement. Will only be executed if statement above. it is true
if (i < 12):
print ("i is smaller than 12 too")
else:
print ("i is greater than 15")
Loop/Repetitive Task/Iteration
These control structures are used for repeated execution of statement(s)
on the basis of a condition. Loop has three main components-
• Start (initialization of loop)
• Step (moving forward in loop )
• Stop (ending of loop)
Python has following loops-
– for loop
– while loop
range () Function
In Python, an important function is range().
Syntax:
range ( <lower limit>,<upper limit>)
If we write
range (0,5 )
Then a list will be created with the values [0,1,2,3,4]
i.e.
from lower limit to the value one less than ending limit.
range (0,10,2) will have the list [0,2,4,6,8]. range (5,0,-1) will have
the list [5,4,3,2,1].
For Loop
The for loop in Python is used to iterate over a sequence
(list, tuple, string) or other iterable objects.
Iterating over a sequence is called traversal.
Syntax:
for val in sequence:
Body of for
# Program to find the sum of all numbers stored in a list
# List of numbers
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
print("The sum is", sum)
for loop with else
A for loop can have an optional else block as well. The else
part is executed if the items in the sequence used in for loop
exhausts.
Example:
digits = [0, 1, 5]
for i in digits:
print(i)
else:
print("No items left.")
output:
0
1
5
While Loop
The while loop in Python is used to iterate over a block of code
as long as the test expression (condition) is true.
We generally use this loop when we don't know the number of
times to iterate beforehand.
Syntax:
while test_expression:
Body of while
Example:
# Program to add natural numbers up to sum = 1+2+3+...+n
# To take input from the user,
n = int(input("Enter n: "))
# initialize sum and counter
sum = 0
i = 1
while i <= n:
sum = sum + i
i = i+1 # update counter
# print the sum
print("The sum is", sum)
Jump Statements
break Statement
while <test-condition>:
statement1
if <condition>:
break
statement2
statement3
Statement4
statemen 5
for <var> in <sequence>:
statement1
if <condition>: break
statement2
statement3
Statement4
statement5
Jump Statements
Example
Python revision tour i
in and not in operator
in operator-
3 in [1,2,3,4] will return True.
5 in [1,2,3,4] will return False.
not in operator-
5 not in [1,2,3,4] will return True.
Jump Statements
continue Statement
The continue statement is used to skip the rest of the code inside a
loop for the current iteration only. Loop does not terminate but
continues on with the next iteration.
Python revision tour i
Part one of Python Revision Tour of
Class XI Completed
Topics
• Strings
• Lists
• Tuples
• Dictionaries
• Sorting Tewchniques
are in next slide
For any querries you may contact me
For reference you check out online
• https://www.programiz.com/python-
programming/first-program
• https://www.w3schools.com/python/
default.asp
Ad

More Related Content

What's hot (20)

Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
Praveen M Jigajinni
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileCBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
ShivaniJayaprakash1
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
Praveen M Jigajinni
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
Praveen M Jigajinni
 
Python file handling
Python file handlingPython file handling
Python file handling
Prof. Dr. K. Adisesha
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Mohammed Sikander
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
Python Decision Making
Python Decision MakingPython Decision Making
Python Decision Making
Soba Arjun
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
12 SQL
12 SQL12 SQL
12 SQL
Praveen M Jigajinni
 
computer science with python project for class 12 cbse
computer science with python project for class 12 cbsecomputer science with python project for class 12 cbse
computer science with python project for class 12 cbse
manishjain598
 
Computer networking For Class XII
Computer networking For Class XIIComputer networking For Class XII
Computer networking For Class XII
Fernando Torres
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
Rishabh-Rawat
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
Praveen M Jigajinni
 
Computer Science Practical File class XII
Computer Science Practical File class XIIComputer Science Practical File class XII
Computer Science Practical File class XII
YugenJarwal
 
Chapter 16 Dictionaries
Chapter 16 DictionariesChapter 16 Dictionaries
Chapter 16 Dictionaries
Praveen M Jigajinni
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileCBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
ShivaniJayaprakash1
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
Praveen M Jigajinni
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Python Decision Making
Python Decision MakingPython Decision Making
Python Decision Making
Soba Arjun
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
computer science with python project for class 12 cbse
computer science with python project for class 12 cbsecomputer science with python project for class 12 cbse
computer science with python project for class 12 cbse
manishjain598
 
Computer networking For Class XII
Computer networking For Class XIIComputer networking For Class XII
Computer networking For Class XII
Fernando Torres
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
Rishabh-Rawat
 
Computer Science Practical File class XII
Computer Science Practical File class XIIComputer Science Practical File class XII
Computer Science Practical File class XII
YugenJarwal
 

Similar to Python revision tour i (20)

chapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdfchapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdf
SangeethManojKumar
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
malekaanjum1
 
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptxpython notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
Elewayte
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
Introduction on basic python and it's application
Introduction on basic python and it's applicationIntroduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
 
Learn about Python power point presentation
Learn about Python power point presentationLearn about Python power point presentation
Learn about Python power point presentation
omsumukh85
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
NehaSpillai1
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
Koteswari Kasireddy
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
HarishParthasarathy4
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 
Review Python
Review PythonReview Python
Review Python
ManishTiwari326
 
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
Saraswathi Murugan
 
chapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdfchapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdf
SangeethManojKumar
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptxpython notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
Devashish Kumar
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
Elewayte
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
Introduction on basic python and it's application
Introduction on basic python and it's applicationIntroduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
 
Learn about Python power point presentation
Learn about Python power point presentationLearn about Python power point presentation
Learn about Python power point presentation
omsumukh85
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
NehaSpillai1
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
Koteswari Kasireddy
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
Saraswathi Murugan
 
Ad

More from Mr. Vikram Singh Slathia (13)

Marks for Class X Board Exams 2021 - 01/05/2021
Marks for Class X Board Exams 2021 - 01/05/2021Marks for Class X Board Exams 2021 - 01/05/2021
Marks for Class X Board Exams 2021 - 01/05/2021
Mr. Vikram Singh Slathia
 
Parallel Computing
Parallel Computing Parallel Computing
Parallel Computing
Mr. Vikram Singh Slathia
 
Online examination system
Online examination systemOnline examination system
Online examination system
Mr. Vikram Singh Slathia
 
Parallel sorting
Parallel sortingParallel sorting
Parallel sorting
Mr. Vikram Singh Slathia
 
Changing education scenario of india
Changing education scenario of indiaChanging education scenario of india
Changing education scenario of india
Mr. Vikram Singh Slathia
 
Gamec Theory
Gamec TheoryGamec Theory
Gamec Theory
Mr. Vikram Singh Slathia
 
Multiprocessor system
Multiprocessor system Multiprocessor system
Multiprocessor system
Mr. Vikram Singh Slathia
 
Sarasvati Chalisa
Sarasvati ChalisaSarasvati Chalisa
Sarasvati Chalisa
Mr. Vikram Singh Slathia
 
Pushkar
PushkarPushkar
Pushkar
Mr. Vikram Singh Slathia
 
Save girl child to save your future
Save girl child to save your futureSave girl child to save your future
Save girl child to save your future
Mr. Vikram Singh Slathia
 
 Reuse Plastic Bottles.
 Reuse Plastic Bottles. Reuse Plastic Bottles.
 Reuse Plastic Bottles.
Mr. Vikram Singh Slathia
 
5 Pen PC Technology (P-ISM)
5 Pen PC Technology (P-ISM)5 Pen PC Technology (P-ISM)
5 Pen PC Technology (P-ISM)
Mr. Vikram Singh Slathia
 
Ad

Recently uploaded (20)

Envenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptxEnvenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptx
rekhapositivity
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Envenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptxEnvenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptx
rekhapositivity
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 

Python revision tour i

  • 1. Computer Science with Python Class: XII Unit I: Computational Thinking and Programming -2 Chapter 1: Review of Python basics I (Revision Tour Class XI) Mr. Vikram Singh Slathia PGT Computer Science
  • 2. Python • In class XI we have learned about Python. In this class we will learn Python with some new techniques. • Python was created by Guido van Rossum. Python got its name from a BBC comedy series – “Monty Python’s Flying Circus”. • Python is based on two programming languages: a. ABC Language b. Module 3 • We know that Python is a powerful and high level language and it is an interpreted language. • Python gives us two modes of working-  Interactive mode It allows us to interact with OS. It executes the code by typing in Python Shell Script mode In this we type python program in a file and then use interpreter to executes the content of the file
  • 3. Tokens • Token is the smallest unit of any programming language. It is also known as Lexical Unit. Types of token are- i. Keywords ii. Identifiers (Names) iii. Literals iv. Operators v. Punctuators i. Keywords Keywords are those words which provides a special meaning to interpreter. These are reserved for specific functioning. These can not be used as identifiers, variable name or any other purpose. Available keywords in Python are-
  • 4. ii. Identifiers • These are building blocks of a program and are used to give names to different parts/blocks of a program like - variable, objects, classes, functions. • An identifier may be a combination of letters and numbers. An identifier must begin with an alphabet or an underscore( _ ) not with any number. • Python is case sensitive. Uppercase characters are distinct from lowercase characters (P and p are different for interpreter). • Keywords can not be used as an identifier. • Space and special symbols are not permitted in an identifier name except an underscore( _ ) sign. • Some valid identifiers are – • Myfile, Date9_7_17, Z2T0Z9, _DS, _CHK FILE13. • Some invalid identifiers are – • DATA-REC, 29COLOR, break, My.File.
  • 5. iv. Literals / Values • Literals are often called Constant Values. • Python permits following types of literals - ◦ String literals – “Pankaj” ◦ Numeric literals – 10, 13.5, 3+5j ◦ Boolean literals – True or False ◦ Special Literal None ◦ Literal collections String Literals String Literal is a sequence of characters that can be a combination of letters, numbers and special symbols, enclosed in quotation marks, single, double or triple(“ “ or ‘ ‘ or “’ ‘”). In python, string is of 2 types- • Single line string Text = “Hello World” or Text = ‘Hello World’ • Multi line string Text = ‘hello or Text = ‘’’hello world’ word ‘’’
  • 6. Numeric Literals  Numeric values can be of three types - • int (signed integers) • Decimal Integer Literals – 10, 17, 210 etc. • Octal Integer Literals - 0o17, 0o217 etc. • Hexadecimal Integer Literals – 0x14, 0xABD etc.  float ( floating point real value) • Fractional Form – 2.0, 17.5 -13.5, -.00015 etc. • Exponent Form - -1.7E+8, .25E-4 etc.  complex (complex numbers) • 3+5i etc. Boolean Literals It can contain either of only two values – True or False Special Literals None, which means nothing (no value).
  • 7. v. Operators An Operator is a symbol that trigger some action when applied to identifier(s)/ operand (s). Therefore, an operator requires operand(s) to compute upon. example : c = a + b Here, a, b, c are operands and operators are = and + which are performing differently. vi. Punctuators In Python, punctuators are used to construct the program and to make balance between instructions and statements. Punctuators have their own syntactic and semantic significance. • Python has following Punctuators - ‘, ”, #, , (, ), [, ], {, }, @. ,, :, .. `, =
  • 9. Variables and Values An important fact to know is- ◦ In Python, values are actually objects. ◦ And their variable names are actually their reference names. Suppose we assign 12 to a variable A = 12 Here, value 12 is an object and A is its reference name. Mutable and Immutable Types Following data types comes under mutable and immutable types- • Mutable (Changeable)  lists, dictionaries and sets. • Immutable (Non-Changeable)  integers, floats, Booleans, strings and tuples.
  • 10. Operators • The symbols that shows a special behavior or action when applied to operands are called operators. For ex- + , - , > , < etc. • Python supports following operators- i. Arithmetic Operator ii. Relation Operator iii. Identity Operators iv. Logical Operators v. Bitwise Operators vi. Membership Operators
  • 11. Operator Associativity In Python, if an expression or statement consists of multiple or more than one operator then operator associativity will be followed from left-to- right. In above given expression, first 7*8 will be calculated as 56, then 56 will be divided by 5 and will result into 11.2, then 11.2 again divided by 2 and will result into 5.0. Only in case of **, associativity will be followed from right-to-left. Above given example will be calculated as 3**(3**2).
  • 12. Type Casting As we know, in Python, an expression may be consists of mixed datatypes. In such cases, python changes data types of operands internally. This process of internal data type conversion is called implicit type conversion. ➢ One other option is explicit type conversion which is like- <datatype> (identifier) For ex- a=“4” b=int(a) Another ex- If a=5 and b=10.5 then we can convert a to float. Like d=float(a) In python, following are the data conversion functions- a. int ( ) b. float( ) c. complex( ) d. str( ) e. bool( )
  • 13. Taking Input in Python • In Python, input () function is used to take input which takes input in the form of string. Then it will be type casted as per requirement. For ex- to calculate volume of a cylinder, program will be as- Its output will be as-
  • 14. Types of statements in Python In Python, statements are of three types: » Empty Statements • pass » Simple Statements (Single Statement) • name=input (“Enter your Name “) • print(name) etc. » Compound Statements <Compound Statement Header>: <Indented Body containing multiple simple statements /compound statements > • Header line starts with the keyword and ends at colon (:) • The body consists of more than one simple Python statements or compound statements.
  • 15. Statement Flow Control In a program, statements executes in sequential manner or in selective manner or in iterative manner. Sequential Selective Iterative
  • 16. If conditional come in multiple forms: • if Condition • if-else condition • if-elif conditional • Nested if statement if Statement An if statement tests a particular condition; If the condition evaluates to true, a course of action is followed. If the condition is false, it does nothing. Syntax: if <condition>: statement(s)
  • 17. if-else Statements If the condition evaluates to true, it carries out statement indented below if and in case condition evaluates to false, it carries out statements indented below else. Syntax: if <condition>: statement(s) when if condition is true else: statement(s) when else case is true dition is false
  • 18. if-elif conditional if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed. The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition". Syntax: if test expression: Body of if elif test expression: Body of elif else: Body of else
  • 20. Example: num = 3.4 if num > 0: print("Positive number") elif num == 0: print("Zero") else: print("Negative number")
  • 21. Nested If -else A nested if is an if statement that is the target of another if statement. Nested if statements means an if statement inside another if statement.
  • 22. Syntax: if (condition1): # Executes when condition1 is true if (condition2): # Executes when condition2 is true # if Block is end here # if Block is end here Example: i = 10 if (i == 10): # First if statement if (i < 15): print ("i is smaller than 15") # Nested - if statement, Will only be executed if statement above it is true if (i < 12): print ("i is smaller than 12 too") else: print ("i is greater than 15")i = 10 if (i == 10): # First if statement if (i < 15): print ("i is smaller than 15") # Nested - if statement. Will only be executed if statement above. it is true if (i < 12): print ("i is smaller than 12 too") else: print ("i is greater than 15")
  • 23. Loop/Repetitive Task/Iteration These control structures are used for repeated execution of statement(s) on the basis of a condition. Loop has three main components- • Start (initialization of loop) • Step (moving forward in loop ) • Stop (ending of loop) Python has following loops- – for loop – while loop
  • 24. range () Function In Python, an important function is range(). Syntax: range ( <lower limit>,<upper limit>) If we write range (0,5 ) Then a list will be created with the values [0,1,2,3,4] i.e. from lower limit to the value one less than ending limit. range (0,10,2) will have the list [0,2,4,6,8]. range (5,0,-1) will have the list [5,4,3,2,1].
  • 25. For Loop The for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects. Iterating over a sequence is called traversal. Syntax: for val in sequence: Body of for
  • 26. # Program to find the sum of all numbers stored in a list # List of numbers numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11] # variable to store the sum sum = 0 # iterate over the list for val in numbers: sum = sum+val print("The sum is", sum)
  • 27. for loop with else A for loop can have an optional else block as well. The else part is executed if the items in the sequence used in for loop exhausts. Example: digits = [0, 1, 5] for i in digits: print(i) else: print("No items left.") output: 0 1 5
  • 28. While Loop The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true. We generally use this loop when we don't know the number of times to iterate beforehand. Syntax: while test_expression: Body of while
  • 29. Example: # Program to add natural numbers up to sum = 1+2+3+...+n # To take input from the user, n = int(input("Enter n: ")) # initialize sum and counter sum = 0 i = 1 while i <= n: sum = sum + i i = i+1 # update counter # print the sum print("The sum is", sum)
  • 30. Jump Statements break Statement while <test-condition>: statement1 if <condition>: break statement2 statement3 Statement4 statemen 5 for <var> in <sequence>: statement1 if <condition>: break statement2 statement3 Statement4 statement5
  • 33. in and not in operator in operator- 3 in [1,2,3,4] will return True. 5 in [1,2,3,4] will return False. not in operator- 5 not in [1,2,3,4] will return True.
  • 34. Jump Statements continue Statement The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.
  • 36. Part one of Python Revision Tour of Class XI Completed Topics • Strings • Lists • Tuples • Dictionaries • Sorting Tewchniques are in next slide For any querries you may contact me
  • 37. For reference you check out online • https://www.programiz.com/python- programming/first-program • https://www.w3schools.com/python/ default.asp