[go: up one dir, main page]

0% found this document useful (0 votes)
10 views7 pages

FINAL PYTHON

The document explains key concepts in Python programming, including data abstraction, data hiding, file opening modes, classes, objects, data structures, and method overloading and overriding. It also covers the differences between lists and tuples, membership and identity operators, and inheritance in Python with examples. Additionally, it provides information on built-in functions, data conversion functions, and the characteristics of mutable and immutable data types.

Uploaded by

privateh085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

FINAL PYTHON

The document explains key concepts in Python programming, including data abstraction, data hiding, file opening modes, classes, objects, data structures, and method overloading and overriding. It also covers the differences between lists and tuples, membership and identity operators, and inheritance in Python with examples. Additionally, it provides information on built-in functions, data conversion functions, and the characteristics of mutable and immutable data types.

Uploaded by

privateh085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

2 MARKS What is data abstruction and data hiding.

State different file opening modes in Python. Abstraction

r: open an existing file for a read operation. Data Abstraction is the process of hiding the internal implementation details and
showing only the essential features of an object.
w: open an existing file for a write operation.
Data hiding.
a: open an existing file for append operation.
Data hiding is a software development technique specifically used in Object-Oriented
r+: To read and write data into the file. Programming (OOP) to hide internal object details (data members).

w+: To write and read data. It will override existing data.


List features of Python.

Define class and object in Python. • Easy to Learn and Use


• Interpreted Language
Class • Interactive Mode
• Free and Open Source
a class is a blueprint for creating objects. It defines attributes (data) and • Platform Independence
methods (functions) that operate on the data. • Object-Oriented Language
Syntax • Extensible

class ClassName: Describe any two data conversion function

def __init__(self): # Constructor


1.int() Function 2. str() Function
# initialize data members
Converts a value into an integer The str() function converts any value
def method_name(self):
(whole number). into a string (text) format.
Object
Example: Example:
An object is an instance of a class that has some attributes and behavior. Objects can be
x = int("10") y = str(100)
used to access the attributes of the class.
print(x) print(y)
Syntax
# Output: 10 # Output: "100"
object_name = ClassName(arguments)
Name different modes of python. Describe mkdir() function
Python has two basic modes: • We can make a new directory using the mkdir() method.
• Script (Normal Mode) • This method takes in the path of the new directory. If the full path is
not specified, the new directory is created in the current working
• Interactive Mode directory.
Syntax: os.mkdir(“newdir”)
Enlist any four data structures used in python.
Lists: Ordered collections of items that can be of any data type, including
strings, integers, floats, and other lists.
Tuples: Ordered, immutable collections of items that can be of any data type.
Dictionary : Unordered collection of key-value pairs.
Sets: Unordered collections of unique items, often used for membership
testing and mathematical operations like union and intersection.

List membership operators in Python.


In: Give result true if value is found in list or in sequence, and give result false
if item is not in list or in sequence
Not in: Give result true if value is not found in list or in sequence, and give
result false if item is in list or in sequence.
Compare list and tuple 4MARKS Explain membership and identity operators in Python.
Membership Operators:
The membership operators in Python are used to find the existence of a
particular element in the sequence, and used only with sequences like string,
tuple, list, dictionary etc.
Membership operators are used to check an item or an element that is part of
a string, a list or a tuple.
Example

Explain four built-in list functions.

Identity Operators :
Identity operators are used to check whether both operands are same or not.
Python provides ‘is’ and ‘is not’ operators which are called identity operators.
Identity Operators are used to check if two values are located on the same part
of the memory or Not.

is: Returns True if two variables refer


to the same object in memory False if
ulat kr
Returns True if two variables do not
refer to the same object. False if ulat
kr rutik
Explain any four file modes in Python with examples.
File modes in Python are used to define how a file should be opened – for
reading, writing, appending, or handling binary data.
'r' – Read Mode
This mode is used to open a file for reading only. The file must already
exist, otherwise an error is raised. It does not allow writing.
Example:
f = open("data.txt", "r")

'w' – Write Mode


This mode opens the file for writing. If the file exists, then content will be
erased. If the file does not exist, a new one is created.
Example:
f = open("data.txt", "w")

Append Mode
This mode opens the file to add new data at the end without deleting the
existing content. If the file does not exist, it creates New File.
Example:
f = open("data.txt", "a")

'b' – Binary Mode


This mode is used to handle binary files like images, audio, or video. It is
used with other modes like 'rb' or 'wb' for reading or writing in binary
format.
Example:
f = open("image.jpg", "rb")
What is data structure and list data structure used in python. Immutable data types – Values cannot be changed. Immutable data types in
A data structure is a way of organizing, storing, and managing data so that it Python are 1. Numbers 2. String 3. Tuple
can be accessed and modified efficiently. Numbers –
The data structures in Python are divided in two categories Mutable and Numbers in Python is like integers and floats. You can’t change the value of a
Immutable number once it is assigned.
Mutable data types – Values can be changed. Mutable data types in Python Example:
are: 1. List 2. Dictionaries 3. Sets
x = 10
List -
print(id(x)) OUTPUT : 10
A list is a data type that allows you to store various types data in it.
To create a list all you have to do is to place the items inside a square bracket
[] separated by comma ,. String-

Example: In Python, strings are immutable, which means you cannot change characters in
the string directly after it's created.
numbers = [1, 2, 3, 4]
Example:
print(numbers) Output: [1, 2, 3, 4]
str = 'rutik'
Set –
str2 = "sakshi"
A set is an unordered collection of unique elements. It does not allow
duplicate values. print(str) Output : rutik

Example: print(str2) sakshi

fruits = {"apple", "banana", "cherry"}


print(fruits) Tuple-

Output: {'apple', 'banana', 'cherry'} A tuple is similar to a list but its immutable. Once a tuple is created, its
elements cannot be modified.
Dictionaries-
Example:
A python dictionary is a collection of key and value pairs separated by a colon
(:) , enclosed in curly braces {}. coordinates = (10, 20, 30)

Example: student = {"name": "John", "age": 25} print(coordinates[1]) Output: 20

print(student["name"]) # Output: John


Explain method overloading and overriding in python. Method Overriding:

Method overloading Method Overriding is the ability of a class to change the implementation of a
method provided by one of its base class.
Method overloading is the ability to define the method with the same name
but with a different number of arguments and data types. To override a method in the base class, we must define a new method with same
name and same parameters in the derived class.
Method overloading is a concept in which a method in a class performs
method overriding a class may "copy" another class, avoiding duplicated code, and
operations according to the parameters passed to it.
at the same time enhance or customize.
this ability one method can perform different tasks, depending on the number
Example -
of arguments or the types of the arguments given.
class Car(Vehicle):
Example-
def start_engine(self):
class Demo:
print("Starting the car's engine... Vroom Vroom!")
def method(self, a):
print(a)
class Motorcycle(Vehicle):
obj= Demo( )
def start_engine(self):
obj.method(50)
print("Starting the motorcycle's engine... Vroom Vroom!")
obj.method('Meenakshi')
obj.method(100.2) OUTPUT-

Starting the car's engine... Vroom Vroom!


Output- Starting the motorcycle's engine... Vroom Vroom!

50
Meenakshi
100.2
Explain inheritance in Python with example.
In Python Inheritance is a feature of Object-Oriented Programming (OOP) that
allows a class to inherit attributes and methods from another class.

Inheritance promotes the reuse of code by allowing a new class to inherit properties
and behaviors from an existing class.

In inheritance, the child class acquires the properties and can access all the data
members and functions defined in the parent class.

Syntax:

class A:

# properties of class A

class B(A):

# class B inheriting property of class A

class Animal:

def sound(self):

print("animal sound")

class Dog(Animal):

def sound(self):

print("Bark")

# Creating objects

animal = Animal()

dog = Dog()

# Calling methods

animal.sound()

dog.sound()

Output - animal sound


bark

You might also like