You are on page 1of 11

LESSON PLAN

CLASS: XII
SUBJECT: COMPUTER SCIENCE
TOPIC: REVIEW OF PYTHON BASICS
TEACHER: Mrs.K.Bhuvanalakshmi
AIM:
To explain about the python basics.
GENERAL OBJECTIVES:
By end of this lesson, children will learn basics of python. Children will be able to work with
Programming questions based on this.
TEACHING AIDS:
White board , marker, Textbook..
WARM UP ACTIVITY:
Children are asked with questions about Python features and its applications.
DESCRIPTIVE EXPLANATION/PRESENTATION:
INTRODUCTION:
Python is a powerful , modern, high-level programming language. Dynamic typing is possible in
python. Python is a dynamic, high level, free open source and interpreted programming language. It
supports object-oriented programming as well as procedural oriented programming.
In Python, we don‟t need to declare the type of variable because it is a dynamically typed language.
For example, x = 10
Here, x can be anything such as String, int, etc.
Features in Python:
There are many features in Python, some of which are discussed below –
1. Easy to code:
Python is a high-level programming language. Python is very easy to learn the language as compared
to other languages like C, C#, Javascript, Java, etc. It is very easy to code in python language and anybody
can learn python basics in a few hours or days. It is also a developer-friendly language.
2. Free and Open Source:
Python language is freely available at the official website and you can download it from the given

1
download Since it is open-source, this means that source code is also available to the public. So you can
download it as, use it as well as share it.
3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming. Python supports object-oriented
language and concepts of classes, objects encapsulation, etc.
4. GUI Programming Support:
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk in
python.
PyQt5 is the most popular option for creating graphical apps with Python.
5. High-Level Language:
Python is a high-level language. When we write programs in python, we do not need to remember the
system architecture, nor do we need to manage the memory.
6. Extensible feature:
Python is a Extensible language. We can write us some Python code into C or C++ language and also
we can compile that code in C/C++ language.
7. Python is Portable language:
Python language is also a portable language. For example, if we have python code for windows and if
we want to run this code on other platforms such as Linux, Unix, and Mac then we do not need to change it,
we can run this code on any platform.
8. Python is Integrated language:
Python is also an Integrated language because we can easily integrated python with other languages
like c, c++, etc.
9. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time. like other
languages C, C++, Java, etc. there is no need to compile python code this makes it easier to debug our code.
The source code of python is converted into an immediate form called bytecode.
10. Large Standard Library
Python has a large standard library which provides a rich set of module and functions so you do not
have to write your own code for every single thing. There are many libraries present in python for such as
regular expressions, unit-testing, web browsers, etc.

1
11. Dynamically Typed Language:
Python is a dynamically-typed language. That means the type (for example- int, double, long, etc.) for a
variable is decided at run time not in advance because of this feature we don‟t need to specify the type of
variable.
MODES OF PYTHON :
1. Interactive Mode (Python Shell): Direct Answer Can be given. It Can‟t be Saved.
2. Script Mode : It Can be Saved.
PYTHON CHARACTER SET :
Character set is the set of valid characters that a language can recognize. A character represents any
letter, digit or any other symbol. Python has the following character sets:
· Letters – A to Z, a to z ·
Digits – 0 to 9 ·
Special Symbols - + - * / etc. ·
Whitespaces – Blank Space, tab, carriage return, newline, formfeed ·
Other characters – Python can process all ASCII and Unicode characters as part of data or literals.

TYPES OF FILE EXTENSION:


. i) py-Normal Python File.
ii).pyc-Compiled byte Code.
iii).pyd-dll Extension.
iv).pyo-Optimization
v).pyw-Windows.
vi).pyz-Archive
STRUCTURE OF A PYTHON PROGRAM:
1. #-Comments
2. Statements does Something with Expressions
3. Functions – eg def a()
4. Blocks – group of Statement
5. Function Call
6. Inline Comments, Multiple Line Comments.

1
VARIABLES & DATA TYPES:
It is a Container to Store Values and it has three Components. They are
1. Value – Given with = (Assignment Operator)
2. Identity – Address of a Variable. Syntax : >>>id (Variable_name)
3. Type – Data Type (String, integer)

DATA TYPES:

1. Number or numeric:
i) Integer and Long
ii) Floating Point
iii) Complex- Real & Imaginary
iv) Boolean – True or False
v) None – Unidentified (absence of Value)
vi) Sequence – Can have both Positive and Negative Values. It is Classified in to Three types. They
are Strings,List & Tuples.
vii) Sets - Unordered Collection of Values. It has no Duplicate entry and it is Mutable.
viii) Mappings- Unordered Collection of Values. It has no Duplicate entry and it is Mutable. Eg
Dictionaries(Key Value Pair). It is enclosed by Curlybraces{}.

DYNAMIC TYPING :
It is defined as a Variable can be used Multiple times within the Same Program. It can save values of
different data types. Eg Integer, String. Every element is consider as an object.
TOKENS :
These are considered as an element of Python Script. Some of the tokens are
i) Identifiers – Name of a Variable, Constant, Function, Module. Eg. Print, Int.
ii) Keywords – These are Reserved Words.
Syntax: Import Keyword
Print( Keyword.kw List)
It will consider only small letters. only False, True, None Starts with the Capital Letters.

1
iii) Literals – Fixed Numeric and Non-Numeric Values.
iv) Operators - + - , .
v) Delimiters – Used as Separators‟ of Values. Eg – (),{},[],;,:,.
Python Comments:
Comments in Python are the lines in the code that are ignored by the interpreter during the execution
of the program. Comments enhance the readability of the code and help the programmers to understand the
code very carefully. There are three types of comments in Python –
 Single line Comments
EXAMPLE:
# Print “GeeksforGeeks !” to console
print("GeeksforGeeks")

 Multiline Comments
EXAMPLE:
""" Python program to demonstrate
multiline comments"""
print("Multiline comments")
 Docstring Comments

PYTHON COLLECTIONS (ARRAYS):


There are four collection data types in the Python programming language:
 List is a collection which is ordered and changeable. Allows duplicate members.
 Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
 Set is a collection which is unordered and unindexed. No duplicate members.
 Dictionary is a collection which is ordered* and changeable. No duplicate members.
STRINGS:
String is a sequence of characters enclosed within quotes. It treats both single and double quotes as equal.
Individual character in the string is accessed using a subscript (index).

1
Strings are immutable. We cannot modify/change the contents of a string after creation. It behaves like a
tuple of characters. Str() function is used to change any type of string.

STRING OPERATIONS:

STRING SLICING:
It is used to retrieve a subset of values. It is called as a substring. Extracted substring is called as a slice.
Syntax:
String_name[start:end:step]
BUILT - IN STRING METHODS:
Some of the methods of strings are:
1. Isalpha()- Returns true only if strings contains only characters.
2. Isdigit()- Returns true only if string contains only digits.
3. Lower()- Converts the uppercase to lowercase letters
4. Islower()- Returns true if all the strings are lowercase.
5. Upper()-Converts the lowercase to uppercase letters.
6. Isupper()-Returns true if all the strings are uppercase.
7. Lstrip() or lstrip(chars)-Returns the string after removing the spaces from the left of the string.
8. Rstrip() or rstrip(chars)- Returns the string after removing the spaces from the right of the string.
9. Isspace()- Returns true if string contains only whitespace.
10. Istitle()- Returns true if all strings are titlecased(all first letters are in Capital).
11. Join(sequence)- String elements are joined by a string operator.
12. Swapcase()- Converts all uppercase to lowercase and vice versa.
13. Partition(separator)- Seperates the mentioned string with quotes.

1
UNPACKING A STRING:
A string can be unpacked in to individual characters.
LISTS:
Lists are mutable. They are a sequence of values and can be changed. The values in the lists are elements,
items or list members. List values are enclosed in Square brackets [].
SYNTAX:
[list_name]=[item1,item2,item3……..itemn]
LIST COMPREHENSION:
It is a concise way of creating a new list from an existing list. It has a for statement inside square
brackets.
LIST SLICING:
These are the sub list extracted from a list using indexes. List slicing means a subset of list whereas
range slicing means extracting individual items.
SYNTAX:
List[start:stop:step]
BUILT IN LIST FUNCTION METHODS:

FUNCTION DESCRIPTION
Cmp(list1,list2) Compare elements from both the lists
Len(list) Returns the total length of the list
Max(list) Returns the item with the maximum value in the list
Min(list) Returns the item with the minimum value in the list
List(seq) Converts a tuple in to a list
Sum(list) Sums up all the numeric values present in the list

LIST METHODS:
1. Append(item): Adds item to the end of the list.
2. Index(item): Returns the index of the item in the list.
3. Insert(index,item): Inserts the item at the specified index.
Invalid index: No exception error will occur.
Index beyond the list: Item add at the end of the list.
Negative index: Item added at the beginning of the list.

1
4. Sort(): Items are sorted in the ascending order.
5. Remove(item): Remove the first occurrence of an item .
Item not found: Value error exception will occur.
6. Reverse(): Reverse the order of items in the list.
COPYING LISTS:
Copy() method creates a duplicate copy , but do not modify items in the list.
SYNTAX:
New_list= list.copy()
TUPLES ():
It is a collection of python objects separated by commas. It is immutable. Tuples are represented by
parentheses ().
ITERATING THROUGH A TUPLES:
Elements of the tuple can be accessed sequentially using range function in the loop. Tuple indices start
at 0.
TUPLE OPERATIONS:
1. Length
2. Concatenation
3. Repetition
4. Membership
5. Iteration
TUPLE SLICING:
It is used to retrieve a subset of values. Slice also called as sub-tuple.
SYNTAX:
Tuple_name[start:stop:step]
UNPACKING TUPLES:
i)Using tuple unpacking.
ii)Using the constructor functions of list() and tuple().
TUPLE FUNCTIONS:
1. Cmp(t1,t2)- Compare elements from both the tuples.
2. Len(tuple)- Returns the length(no of elements) in the tuple.
3. Max(tuple)- Returns the item with the maximum value.

1
4. Min(tuple)- Returns the item with the minimum value.
5. Tuple(seq)- Converts a list in to tuple.
6. Del(tuple)- deletes entire tuple.
7. Sorted(tuple)- sort the values in ascending order.
8. Sorted(tuple, reverse=true)- sort the values in descending order.
9. Sum(tuple)- Add all values.
DICTIONARY:
It is accessed using a unique key(number,string,tuple). The items in a dictionary can be changed, keys
are immutable. Key-value pair are enclosed in curly braces{}.
SYNTAX:
<dictionary_name> = {„key1‟:‟value1‟,……….‟keyn‟:‟valuen‟}

ITERATING THROUGH DICTIONARY:

UPDATING DICTIONARY ELEMENTS:


Modifying an existing key value pair or merging a new dictionary with another one.
SYNTAX:
<dictionary>[<key>]=,value>
EXAMPLE: For updating the value of key already present in the dictionary.

1
EXAMPLE: For updating the value of key, if it is not present in the dictionary.

BUILT IN DICTIONARY FUNCTIONS:


1. Cmp(dict1,dict2) – Compares the elements from both the dictionaries.
2. Len(dict) – Returns the total number of items from the dictionaries.
3. Str(dict) – Produces a printable string representation of a dictionary.
4. Type(variable) – Returns the type of variable passed as an argument.
BUILT IN DICTIONARY METHODS:
1. Dicty.clear() – Remove all elements from a dictionary.
2. Dict.copy() – Returns a copy of dictionary.
3. Dict.items() – Returns a list of key, value pairs.
4. Dict.keys() – Returns the dictionary keys.
5. Dict.setdefault(key,default=none) – set key with the default value, if it not already present in the dictionary.
6. Dict.update(dict) – Add new dictionary values.
7. Dict.values() – Returns a list of dictionary values.

1
ACTIVITIES:
Python basics are practiced in the lab.
RECAPITULATION:
Children are asked about evolution of python.

CLASSWORK
1. Write a program to find a maximum, minimum, and a mean value of elements in a list.

2. Write a python program to create a list of 7 cities and then


a) Display all the elements in the list.
b) Display all the elements in reverse order.

You might also like