Please refer to Revision of the basics of python Class 12 Computer Science Notes and important questions below. The Class 12 Computer Science Chapter wise notes have been prepared based on the latest syllabus issued for the current academic year by CBSE. Students should revise these notes and go through important Class 12 Computer Science examination questions given below to obtain better marks in exams
Revision of the basics of python Class 12 Computer Science Notes and Questions
The below Class 12 Revision of the basics of python notes have been designed by expert Computer Science teachers. These will help you a lot to understand all the important topics given in your NCERT Class 12 Computer Science textbook. Refer to Chapter 10 Revision of the basics of python Notes below which have been designed as per the latest syllabus issued by CBSE and will be very useful for upcoming examinations to help clear your concepts and get better marks in examinations.
- Python (a computer language) :
- Python is a powerful and high level language and it is an interpreted language.
- It is widely used general purpose, high level programming language developed by Guido van Rossum in 1991.
- Python has two basic modes: interactive and script.In interactive mode (python.exe/py.exe), the result is returned immediately after pressing the enter key. In script mode (IDLE), a file must be created and saved before executing the code to get results.
Basics of Python: Output img
Simple Hello world Program print(‘hello world’) print(“HELLO WORLD”) | Output hello world HELLO WORLD |
Declaring/Defining variable a=10 b=20 c=a+b print(c) d,e=2,3 print(d,e) | Output 30 2 3 |
Output Formatting a,b=10,20 c=a+b print(“The addition of a and b is “, c) print(“The addition of “,a,”and “, b, “is “,c) print(“The addition of %d and %d is %d” %(a,b,c)) | Output The addition of a and b is 30 The addition of 10 and 20 is 30 The addition of 10 and 20 is 30 |
name=”XYZ” age=26 salary=65748.9312 print(“The age of %s is %d and salary is %.2f”%(name,age,salary)) | Output The age of XYZ is 26 and salary is 65748.93 |
Basics of Python: Input
Accepting input without prompt name=input() print(name) | Output Govind Govind |
Accepting input with prompt name=input(“Enter your name : “) print(“My name is “,name) | Output Enter your name : Govind My name is Govind |
Accepting formatted input (Integer, float, etc.) a=int(input(“Enter any integer number :”)) b=float(input(“Enter any float number :”)) print(“Entered integer is : “,a) print(“Entered float is : “,b) | Output Enter any integer number :10 Enter any float number :3.14 Entered integer is : 10 Entered float is : 3.14 |
Keywords in Python
There are 33 keywords in Python 3.7. This number can vary slightly in the course of time. All the keywords except True, False and None are in lowercase and they must be written as it is. The list of all the keywords is given below.
and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try
Operators in Python
Python language supports the following types of operators-
- Arithmetic Operators
- Relational Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Membership Operators
- Identity Operators
Operators in Python: Arithmetic
Assume a=10 and b=20

Operators in Python: Relational
Relational Operators are used to show relationship between two values or variables. Following are the relational operators
< (less than), >(greater than) , <= (less than equal to), >= (greater than equal too) ,!= (Not equal to) and = = (equality check operator)
Logical Operator in Python

Operators in Python: Assignment

Operators in Python: Bitwise
Bitwise operator works on bit and performs bit by bit operation. Assume if –
A=60 and B=13; now in binary they will be as follows
A(60)=00111100
B(13)=00001101
a&b = 0000 1100 (Use of bitwise Binary AND)
a|b = 0011 1101 (Use of bitwise Binary OR)
a^b = 0011 0001 (Use of bitwise XOR)
~a = 1100 0011 (Use of ones complement)
Operators in Python: Membership

Operators in Python: Identity

Control Statements in Python
Control statements are used to control the flow of execution depending upon the specified condition/logic.
There are three types of control statements-
1. Decision Making Statements (if, elif, else)
2. Iteration Statements (while and for Loops)
3. Jump Statements (break, continue, pass)
Decision Making Statements (if, elif, else) Syntax: if(logic): Statement/s elif(logic): Statement/s else: Statement/s | Program a=int(input(“Enter any integer number :”)) if(a==0): print(“Number is Zero”) elif(a>0): print(“Number is Positive”) else: print(“Number is negative”) | Output Enter any integer number :5 Number is Positive |
Iteration Statements (while loop) Syntax: while(condition): Statement/s | Program n=1 while(n<4): print(“Govind “, end=“ “) n=n+1 | Output Govind Govind Govind |
Iteration Statements (for loop) Syntax: for value in sequence: Statement/s | Program for i in range(1,6): print(i, end=’ ‘) | Output 1 2 3 4 5 |
Jump Statements (break, continue, pass) Syntax for val in sequence: if (val== i): break if (val== j): continue if (val== k): pass | Program for i in range(1,11): if(i==3): print(“hello”, end=’ ‘) continue if(i==8): break if(i==5): pass else: print(i, end=’ ‘); | Output 1 2 hello 4 6 7 |
List in Python

Creating a list and accessing its elements a=[10,20,’abc’,30,3.14,40,50] print(a) for i in range(0,len(a)): print(a[i], end=’ ‘) print(‘\n’) for i in range(len(a)-1,-1,-1): print(a[i], end=’ ‘) print(‘\n’) for i in a[::-1]: print(i, end=’ ‘) print(‘\n’) for i in reversed(a): print(i, end=’ ‘) | Output [10, 20, ‘abc’, 30, 3.14, 40, 50] 10 20 abc 30 3.14 40 50 50 40 3.14 30 abc 20 10 50 40 3.14 30 abc 20 10 50 40 3.14 30 abc 20 10 |
Tuple in Python img
It is a sequence of immutable objects. It is just like a list. Difference between a tuple and a list is that the tuple cannot be changed like a list. List uses square bracket whereas tuple use parentheses.
L=[1,2,3,4,5] Mutable Elements of list can be changed
T=(1,2,3,4,5) Immutable Elements of tuple can not be changed
Creating a tuple and accessing its elements a=(10,20,’abc’,30,3.14,40,50) print(a) for i in range(0,len(a)): print(a[i], end=’ ‘) print(‘\n’) for i in range(len(a)-1,-1,-1): print(a[i], end=’ ‘) print(‘\n’) for i in a[::-1]: print(i, end=’ ‘) print(‘\n’) for i in reversed(a): print(i, end=’ ‘) | Output (10, 20, ‘abc’, 30, 3.14, 40, 50) 10 20 abc 30 3.14 40 50 50 40 3.14 30 abc 20 10 50 40 3.14 30 abc 20 10 50 40 3.14 30 abc 20 10 |
Function | Description |
tuple(seq) | Converts a list into a tuple. |
min(tuple) | Returns item from the tuple with min value. |
max(tuple) | Returns item from the tuple with max value. |
len(tuple) | Gives the total length of the tuple. |
cmp(tuple1,tuple2) | Compares elements of both the tuples. |
Dictionary in Python
Dictionary in Python is an unordered collection of data values, used to store data values along with the keys. Dictionary holds key:
value pair. Key value is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a colon:, whereas each key is separated by a ‘comma’.
dict={ “a”: “alpha”, “o”: “omega”, “g”: ”gamma” }

Creating an empty Dictionary Dict = {} print(“Empty Dictionary: “) print(Dict) Creating a Dictionary with Integer Keys Dict = {1: ‘AAA’, 2: ‘BBB’, 3: ‘CCC’} print(“\nDictionary with the use of Integer Keys: “) print(Dict) Creating a Dictionary with Mixed keys Dict = {‘Name’: ‘Govind’, 1: [10, 11, 12, 13]} print(“\nDictionary with the use of Mixed Keys: “) print(Dict) Creating a Dictionary with dict() method D=dict({1: ‘AAA’, 2: ‘BBB’, 3:’CCC’}) print(“\nDictionary with the use of dict(): “) print(D) Creating a Dictionary with each item as a Pair D=dict([(1, ‘AAA’), (2, ‘BBB’)]) print(“\nDictionary with each item as a pair: “) print(D) | Output Empty Dictionary: {} Dictionary with the use of Integer Keys: {1: ‘AAA’, 2: ‘BBB’, 3: ‘CCC’} Dictionary with the use of Mixed Keys: {‘Name’: ‘Govind’, 1: [10, 11, 12, 13]} Dictionary with the use of dict(): {1: ‘AAA’, 2: ‘BBB’, 3: ‘CCC’} Dictionary with each item as a pair: {1: ‘AAA’, 2: ‘BBB’} |
Creating an empty Dictionary Dict = {} print(“Empty Dictionary: “) print(Dict) Adding elements one at a time Dict[0] = ‘Govind’ Dict[2] = ‘Prasad’ Dict[3] = ‘Arya’ print(“\nDictionary after adding 3 elements: “) print(Dict) Adding set of values to a single Key Dict[‘V’] = 1, 2 print(“\nDictionary after adding 3 elements: “) print(Dict) Updating existing Key’s Value Dict[‘V’] = 3,4 print(“\nUpdated dictionary: “) print(Dict) | Empty Dictionary: {} Dictionary after adding 3 elements: {0: ‘Govind’, 2: ‘Prasad’, 3: ‘Arya’} Dictionary after adding 3 elements: {{0: ‘Govind’, 2: ‘Prasad’, 3: ‘Arya’} , ‘V’: (1, 2,)} Updated dictionary: {{0: ‘Govind’, 2: ‘Prasad’, 3: ‘Arya’} , ‘V’: (3, 4,)} |
Creating a Dictionary D = {1: ‘Prasad’, ‘name’: ‘Govind’, 3: ‘Arya’} accessing a element using key print(“Accessing a element using key:”) print(D[‘name’]) accessing a element using key print(“Accessing a element using key:”) print(D[1]) accessing a element using get() method print(“Accessing a element using get:”) print(D.get(3)) | Output Accessing a element using key: Govind Accessing a element using key: Prasad Accessing a element using get: Arya |
D={1:’AAA’, 2:’BBB’, 3:’CCC’} print(“\n all key names in the dictionary, one by one:”) for i in D: print(i, end=’ ‘) print(“\n all values in the dictionary, one by one:”) for i in D: print(D[i], end=’ ‘) print(“\n all keys in the dictionary using keys() method:”) for i in D.keys(): print(i, end=’ ‘) print(“\n all values in the dictionary using values() method:”) for i in D.values(): print(i, end=’ ‘) print(“\n all keys and values in the dictionary using items()method:”) for k, v in D.items(): print(k, v, end=’ ‘) | Output all key names in the dictionary, one by one: 1 2 3 all values in the dictionary, one by one: AAA BBB CCC all keys in the dictionary using keys() method: 1 2 3 all values in the dictionary using values() method: AAA BBB CCC all keys and values in the dictionary using items()method: 1 AAA 2 BBB 3 CCC |