12th Standard Syllabus & Materials
12th Standard
TN 12th English Poem - 6 - Incident of the French Camp Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 6 - On the Rule of the Road Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 5 - The Chair Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 4 - The Midnight Visitor Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 4 - Ulysses Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 4 - The Summit Sample Question Papers Study Material - QB365 Set A

Published on: 03/12/2019
Python Classes and Objects
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
Which of the following is valid syntax for crating objects?
objectname = classname ()
objectname: classname ()
objectname = classname
classname = Objectname ()
2.
Functions of the class are called as
Methods
Members
Variables
Loog
3.
Which of the following is the private class variable?
__num
##num
$$num
&&num
4.
Which of the following method is used as destructor?
__init__( )
__dest__( )
__rem__( )
__del__( )
5.
A private class variable is prefixed with
__
&&
##
**
6.
Write a note on public and private data members of python class.
7.
Write a program in python that illustrate the use of constructor.
8.
Differentiate python class function and ordinary function.
9.
10.
What is instantiation?
11.
Read the following program. Answer the following question. Class sample:
x, y= 10, 20
s= sample ()
print (s. x + s. y)
1. What does sample denotes?
2. What does x, y denotes?
3. What does s denotes?
12.
Write a python program that illustrate the use of destructor.
13.
Write a python program to find total and average marks using class.
14.
How to define constructor and destructor in Python?
15.
Write a class with two private class variables and print the sum using a method.
16.
Write a program to accept a string and print the number of uppercase, lowercase, vowels, consonants and spaces in the given string.
17.
Write a menu driven program that keeps record of books available in you school library.
1.
(c)
objectname = classname
2.
(a)
Methods
3.
(a)
__num
4.
(d)
__del__( )
5.
(a)
__
6.
(i) The variables which are defined inside the class is public by default. These variables can be accessed anywhere in the program using dot operator.
(ii) A variable prefixed with double underscore becomes private in nature. These variables can be accessed only within the class
7.
Program to illustrate Constructor:
class Sample:
def _init_(self, num):
print("Constructor of class Sample...")
self.num=num
print("The value is :", num)
S = Sample(10)
Output:
constructor of class Sample..
The value is:10
8.
Python class function or method is very similar to ordinary function with a small difference. The class method must have the first argument named as self.
9.
10.
Once a class is created, next to create an object or instance of that class. This process of creating object is called as "Class Instantiation".
11.
1. It denotes class name
2. x, y is a class variables of the class
3. S is an object created to access the members of the class
12.
Program to illustrate about the _del_( ) method
class Sample:
num=()
def _init_(self, var):
Sample.num+= 1
self.var=var
print("The object value is = ", var)
print("The value of class variable is = ", Sample.num)
def _del_(self):
Sample.num-=1
print("Object with value %d is exit from the scope"%self.var)
S1=Sample(15)
S2=Sample(35)
S3=Sample(45)
13.
class Student:
mark1, mark2, mark3 = 45, 91, 71
#class variable
#class method
def process(self):
sum = Student.mark1 + Student.mark2 + Student.mark3
avg = sum/3
print("Total Marks = ", sum)
print("Average Marks = ", avg)
return
S=Student()
S.process()
Output:
Total marks = 207
Average Marks = 69.0
14.
Constructor :
(i) Constructor is the special function that is created. In Python, there is a special function called "init", which act as a constructor.
(ii) It must begin and end with double underscore.
General format of Constructor :
General format of _init_ method (Constructor function)
def _init_(self, [args .... ]):
<statement>
Destructor :
(ii) In Python,_del_() method is used as destructor.It is just opposite to constructor.
15.
Code:
class Sample:
def_init_(self, n1, n2):
self._n1=nt
self_n2-n2
def sum(self):
print ("Class Variable 1:" self_n1)
print ("Class Variable 2:", self_n2)
S=Sample (5,10)
S.sum()
Output:
Class Variable 1:5
Class Variable 2: 10
Sum: 15
16.
Class String:
def _init_(self):
self.uppercase=()
self.lowercase=()
self.vowels=()
self.consonants=()
self.spaces=()
self.string= " "
def getstr (self):
self.string=str(input("Enter a String: "))
def count_upper(self):
for ch in self.string:
if (ch.isupper()):
self.uppercase+= 1
def count_Iowert(self):
for ch in self.string:
if (ch.islower()):
self.lowercase+= 1
def count_vowels(self):
for ch in self.string:
if (ch in ('A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')):
self.vowels+=1
def count_consonants(self):
for ch in self.string:
if (ch not in ('A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')):
self.consonants+= 1
def count_space(self):
for ch in self.string:
if (ch==" ''):
self.spaces+= 1
def execute(self):
self.count_upper()
self.count_lower ()
self.count_vowels ()
self.count_consonants()
self.count_space()
def display(self):
print("The given string contains ...")
print("%d Uppercase letters"%self. uppercase)
print("%d Lowercase letters"%self. lowercase)
print("%d Vowels"%self.vowels)
print("%d Consonants"%self.consonants)
print("%d Spaces"%self.spaces)
S = String()
S.getstr()
S.execute()
S.display()
Output:
Enter a string: Welcome To Learn Computer Science
The given string contains...
5 Uppercase letters
24 Lowercase letters
13 vowels
20 consonants
4 Spaces
17.
class Library:
def _init_(self):
self.bookname= ""
self.author='"
def getdata(self):
self.bookname = input("Enter Name of the Book: ")
self.author = input("Enter Author of the Book: ")
def display(self):
print("Name of the Book: ",self.bookname)
print("Author of the Book: ",self.author)
print("\n")
book= [] #empty list
ch = 'y'
while( ch=='y'):
print("1. Add New Book \n 2.Display Books")
resp = int(input("Enter your choice: "))
if(resp==1):
L=Library()
L.getdata()
book.append(L)
elif(resp==2):
for x in book:
x.display()
else:
print("Invalid input....")
ch = input("Do you want continue ....")
Output
1. Add New Book
2. Display Books
Enter your choice: 1
Enter Name of the Book: Programming in C++
Enter Author of the Book: K. Kannan
Do you want to continue...y
1. Add New Book
2. Display Books
Enter your choice: 1
Enter Name of the Book: Advanced Python
Enter Author of the Book: Dr. vidhya
Do you want continue.... n
12th Standard Syllabus & Materials
12th Standard
TN 12th English Supplementary - 3 - The Hour of Truth (Play) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 3 - All the World’s a Stage Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 3 - In Celebration of Being Alive Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 2 - Life of Pi Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards