new topics Flashcards

1
Q

inheritance

A
  1. Inheritance provides code reusability to the programme because we can use an existing class to create a new class instead of creating it from scratch
    2Here child class acquires the properties and can access all the data members and functions defined in the parent class and Child class also can provide its specific implementation to the functions of parent class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

simple inh
multi lvl
multiple inh

A

Simple inheritance
cls derived-class(base class):

<class-suite>
(or)
cls derived-class(<basecls 1>\_\_\_\_<basecla>):
<class-suite>
**Multi level inheritance**
cls cls1:
<class-suite>
class cls2(cls1:
<class-suite>
cls cls3(cls2):
<class-suite>
Multiple inheritance
cls cls1(basecls1, basecls2, basecls3_ _ _):
<class-suite>
</class-suite></class-suite></class-suite></class-suite></class-suite></basecla></class-suite>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

issubclass(sub, sup)

A

return true if the sp. class is subclass of the Super Class and false for vv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The isinstance (obj, class)

A
  1. checks The relationship between objects and classes
  2. Returns true if the first parameter(obj) Is the instance of second parameter(cls)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Method overriding

A
  1. When parent class method is defined in child class with some specific implementation then this concept is called as method overriding
  2. This scenario is used when different definition of parent class is declared in child class
    eg:
    cls animal:
    def speak(self):
    print(“speaking”)
    class dog(animal):
    print(“barking”) #decl in p-cls as speaking and in c-cls as barking—-method overriding
    d=dog()
    d.speak()
    o/p:
    barking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

real life eg on Method overriding

A

class Bank:
def getroi(self):
return 10;
class SBI(Bank):
def getroi(self):
return 7;

class ICICI(Bank):
def getroi(self):
return 8;
b1 = Bank()
b2 = SBI()
b3 = ICICI()
print(“Bank Rate of interest:”,b1.getroi());
print(“SBI Rate of interest:”,b2.getroi());
print(“ICICI Rate of interest:”,b3.getroi());

o/p:
Bank Rate of interest: 10
SBI Rate of interest: 7
ICICI Rate of interest: 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Abstraction

A
  1. Abstractions used to hide the internal functionality of the function from the users
  2. The uses only interact with the basic implementation of the function but the inner working is hidden
  3. Abstraction is used to hide the relevant data or class in order to reduce the complexity
  4. It also enhances the efficiency of the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

abs cls in py

A
  1. Abstraction can be achieved by abstract classes and interfaces
  2. A class that consists of one or more abstract method is called as abstract class
  3. Abstract methods do not contain their implementation
    4.** Abstract class can be inherited by the subclass and abstract method gets its definition in the subclass**
  4. abstract classes are meant to be the blueprint of other classes they are used in designing large functions
  5. Python provides **abc module **to use abs in py progs
  6. abc works by decorating methods of base class as abstract
  7. We use @abstractmethod Decorator to define abstract method or if you don’t provide definition to the method it automatically becomes the abstract method
    **9. An abstract class contain both Normal method and abstract method
  8. We cannot create objects for abstract class**

syn:
from abc import ABC
class classname(ABC):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

encapsulation

A
  1. wrapping data and methods that work with data in one unit
  2. This prevents data modification accidentally by limiting access only to variables and methods
  3. An object’s method Can change a variable’s value to prevent accidental changes these variables are called as private variables

protected datamem: The ones which can be accessed And modified by the class and in the derived class
- single underscore(_)

Private datamem: Cannot be accessed by anyone outside of the class or except the class in which it is declared
-double underscore(_ _)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

polymorphism

A
  1. Having multiple forms
  2. Refers to use of same function name but with different signature for multiple types

eg:
pre-def:
print (len(“Javatpoint”))
print (len([110, 210, 130, 321]))
user-def:
def add(p, q, r = 0):
return p + q + r
print (add(6, 23))
print (add(22, 31, 544))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

poly in cls

A

class xyz():
def websites(self):
print(“Javatpoint is a website out of many availabe on net.”)

def topic(self):  
    print("Python is out of many topics about technology on Javatpoint.")  
  
def type(self):  
    print("Javatpoint is an developed website.")  

class PQR():
def websites(self):
print(“Pinkvilla is a website out of many availabe on net. .”)

def topic(self):  
    print("Celebrities is out of many topics.")  
  
def type(self):  
    print("pinkvilla is a developing website.")  

obj_jtp = xyz()
obj_pvl = PQR()
for domain in (obj_jtp, obj_pvl):
domain.websites()
domain.topic()
domain.type()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

lamda

A
  1. Lambda functions in python are anonymous functions imply they dont have a name
  2. TEF keyword is needed to create a typical functional python but We can also define unnamed function with the help of Lambda
    keyword
  3. this func accepts a any count of inputs but only evaluates and returns one output

syn:
identifier=lambda args:expr
calling:
print (indientifier(value))
here,
identifier is like a function name
args can be any number
expr–expr using those args

eg:
a=lambda x,y:(x*y)
print(a(3,4))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Difference between Lambda and Def function

A
  1. Infunction we need to declare a function with name and send args to it While executing def
  2. We’re also required to use return keyword to provide output function was invoked after big executed
  3. But in Lambda function during its definition itself a statement is included which is given as output
  4. Beauty of Lambda function is there a convenience we need not to allocate a Lambda expression to a variable because we can put it any place a function requested
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

filter() with lambda

A
  1. Fulton method accepts two arguments in python a function and an iterable such as list
  2. The function is called for the every item of the list, and a new iterable or list is returned that holds just those ele that returned true when supplied to function
    eg:
    list1=[1,2,3,4,5]
    oddlist=list(filter(lambda num: (num%2!=0),list1))
    print(oddlist)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

map() with lambda

A
  1. A method and Lister passed in map()
  2. The function is executed for all the elements in the list and then a new list is produced the elements generated by given function for everyitem
  3. eg:
    numbers_list = [2, 4, 5, 1, 3, 7, 8, 9, 10]
    squared_list = list(map( lambda num: num ** 2 , numbers_list ))
    print( ‘Square of each number in the given list:’ ,squared_list )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

list comprehension

A

syn:
listname=[expr for var in seq]
benefits:
1. List comprehension as an alternative for loops and maps
2. We can Utilise list comprehension as single tool to solve many circumstances
3. We dont need to remember appropriate order of parameters when using list comprehension
4. Easy to use

eg:
list1=[1,2,3,4,5]
list2=[i* *2 for i in list1]
print(list2)

list2=[i* *2 for i in range(1,6)]
print(list2)

17
Q

List to comprehension to tuple

A

We used list comprehension to create a new list as in the same way we can use it to manipulate the values in one tuple to new tuple

eg: def double(t):
return [i**2 for i in t]
tuple1=1,2,3,4,5
print(tuple1)
print(double(tuple1))

17
Q

iterators and iterables

A
  1. iterables:Any py object Capable of returning its element one at a time is an interable
  2. eg: List dictionaries tuples set strings etc
  3. You can look through an iterable using for loop for a comprehension
  4. Iterator: Iterator is an object that can be iterated upon meaning that you can traverse through the values
  5. It It has two methods:
    __iter__()–Returns iterator object (like i)
    __next__()– Returns the next value from the iterator if there are no more items it raises stop iteration exception
18
Q

zip()

A
  1. Built in function that takes two or more sequences(list,tuple….) and zips them together into a list of tuples

eg:
tuple1=(1,2,3,4,5)
list1=[a,b,c,d,e]
print(list((zip(tupl1, list1))

here no. of value is not equal, then
tuple1=(1,2,3,4,5)
list1=[1,2,3]
print(list((zip(tuple1, list1))))

19
Q

enumerate function

A
  1. Enumerate function is built in function that helps in traversing the elements of a sequence and print their indices
    for i, j in enumerate(“abcdefgh”):
    print(i, j)
20
Q

dict compr

A

{key_expr: value_expr for item in ierable}

eg:
fruits={apple, banana}
flen={f : len(f) for f in fruits}
print(flen)

21
Q

Console input output

A

Console Output:
1. Print() function is used to display information messages and result on console
2. Print() function takes one or more arguments and displays them as text in console

Console Input:
1. Input() Function is used to take the input from console
2. It reads the line entered by the user and returns it as string
3. Input() Always returns as string we need to mention the data type for the other than str
4. We can also put f-strings or str.format() to format the o/p
eg:
name=manasa
print(f”hello {name}”)

name = input(“Enter your name: “)
age = int(input(“Enter your age: “))

print(f”Hello, {name}!”)
print(f”You are {age} years old.”)

22
Q

What is an expression in python

A
  1. Expression is a combination of values variables operators and function calls that can be evaluated to produce a result
  2. Expressions are the building blocks of python code and are used to perform computations manipulate data and make decisions

Explain about values variables operators function calls combinations and evaluation

23
Q

python intro

A
  • Introduced by Gudio Van Rossam 1991
  • Python is general purpose dynamic high level and interpreted programming language
  • It supports OOP approach to develop applications
  • It is very simple and easy to learn and provides lots of high level data structures
  • It Allows both scripting and interactive mode
24
Q

Advantages of python

A
  1. Easy to learn
  2. Expressive language
  3. Interpreted language
  4. oo Language
  5. Open source language
  6. GUI programming support
  7. Integrated
  8. Dynamic memory allocation
  9. Career opportunities
  10. High demand
  11. Big data and machine learning
25
Q

Applications of python

A
  1. Web development
  2. Software development
  3. Mathematics
  4. Systems scripting
  5. Systems To connect to database and read or modify files
  6. Rapid prototyping
  7. Handles big data and perform complex mathematics
  8. Console based applications
  9. Data science
  10. Desktop applications
  11. Mobile applications
26
Q

features of py

A
  1. Easy to learn and use
  2. expressive language
  3. interpreted language
  4. Portable language
  5. free and open source
  6. OO language
  7. extensible
  8. large standard library
  9. GUI programming support
  10. integrated
  11. embeddable
  12. dynamic memory allocation
27
Q

Python history

A
  1. python laid its foundation in late 1980s
  2. The implementation of python is started in December 1989 by Judio Van Ross in Netherlands
  3. In February 1991 Gudio Van Rossam published the code
  4. In 1994 python 1.0 was released with new features like** Lambda map filter and reduc**e
  5. Python 2.0 added new feature such as list comprehension garbage collection etc
  6. Abc programming language is set to be Predecessor of python language is capable of exception handling and interfacing with amoeba operating systems
  7. Abc Language, Modula-3 are languages which influenced python
28
Q

Current version of python

A

3.10 .4

29
Q

Identifiers

A
  1. One user defined name given to a variable function or a class or a module
  2. it is a combination of digits and an _
  3. they are case sensitive
  4. There are three valid identifiers letters digits and _
30
Q

String formatting

A
  1. Using F strings
    F strings are also known as formatted string literals or concise and readable way to format strings
    - They are prefixed by F and And embedded in curly brackets{}
    name = “Alice”
    age = 30
    formatted_string = f”My name is {name} and I am {age} years old.”
    print(formatted_string)
  2. Using str.format() meth
    This method allows you to create formatted string by specifying placeholder within curly brackets and providing values to replace them
    name = “Bob”
    age = 25
    formatted_string = “My name is {} and I am {} years old.”.format(name, age)
    print(formatted_string)
  3. using %
    using Module Operator to format strings
    name = “Charlie”
    age = 35
    formatted_string = “My name is %s and I am %d years old.” % (name, age)
    print(formatted_string)
  4. Using Concatenation
    name = “David”
    age = 40
    formatted_string = “My name is “ + name + “ and I am “ + str(age) + “ years old.”
    print(formatted_string)
  5. Using Interpolation
    8 python 3.8 introduced a new method called F strings interpolation that allows you to use F prefix followed by string without curly brackets
    name = “Eve”
    age = 50
    formatted_string = f”My name is {name = }, and I am {age = } years old.”
    print(formatted_string)
31
Q

Operations on list, touple

A
  1. Repetition(list*2)
  2. Concatenation (+)
  3. Membership(in , not in)
  4. Iteration(for)
  5. len()
32
Q

list meth 8

A

Insert
extend
remove
pop
clear
sort
copy
append

33
Q

tuple meth 8

A
  1. LEN
  2. count
  3. min
  4. max
  5. zip
  6. sort
  7. sum
  8. index
34
Q

set 12

A
  1. Union
  2. intersection
  3. difference
  4. symmetric difference
  5. update
  6. remove
  7. discard
  8. Add
  9. pop
  10. clear
  11. del
  12. copy