Q1. What Is Python
Q1. What Is Python
What is python
• Python is high level, interpreted, interactive, and object oriented
programming language
• Today in programming language is the Python is trendiest programming
language
• Python is popular programming language because it provides more
realibility of code, clean syntax of code, advanced language features,
scalability of code, portability of code, support object oriented
programming, easy to learn and read, support GUI mode, interactive,
interpreted, interface to all major commercial database and so on
Q4. Variables
• Variables is like a container that stores the value that we can change or
access
• It is way of pointing to the memory location used by program
• Variable is a name given to location in computer program memory location
Where value can be stored that can used in program
• When we create a variable some space in memory is reserved or allocated
for that variable to store the data value in it
• The variable is so called because it's value may vary (change) during the
time of execution
1. Arithmetic operator
• Arithmetic operator are used to perform mathematical operations like
addition subtraction multiplication etc
2. Logical operator
• Logical operator are used to perform logic operations like and or not and to
come by two or more conditions to provide a specific result that is true or
false
3. Comparison operator
• Comparison operator are used to compare value either it returns true or
false according to the condition
4. Assignment operator
• Assignment operator are used in Python to assign value to variable
• There is a various assignment operator that is :
= += -+ *= /= %= |=
5. Bitwise operator
• Bitwise operator acts on operands. It operate bit by bit hence the name is
bitwise
Q20 package
• Suppose we have developed a very large application that includes many
modules. As the number of module grows it become difficult to keep track
of them all as they have similar name or functionalities.
• The Python provide to keep track this all with the help of package
• To group and organise that module is done by package
• Packages a hierarchical file dictionary structure that defines a single Python
application environment that consist of modules and subpackages and sub-
subpackages and so on
• A package the collection of python modules
3rd lesson
Q21. What is class and object in Python
1. class
• Programmer use class to keep related things together
• This is done using the keyword class which is grouping of object-oriented
constructs
• A class is like a blueprint of object.
2.object
• Object is an instance of class
• A class is like a blueprint while instance is copy of the class with actual value
• Object consist of state, behavior and identity
1. State: represent the attribute of an object
2. Behavior: represents by the method of an object
3. Identity: it gives unique name to an object and enable one object to
interact with another object
Q22.How to creating class and objects
• Python classes are the data structures used to define objects. A class is a
object constructor or blueprint for the creating object.
• To define class you need to consider following points
Step 1: in Python classes are defined by the class keyword
class MyClass ():
Step 2: inside classes you can define function or method that are the part of
the this class
def method1 (self):
print "Nirali Prakashan"
def method2 (self,somestring):
print"software testing:"+somestring
• Here we have defined method one that prints Nirali Prakashan.
• Another method we have defined is method to that prints software testing
+ some string.
• Some string is the variable supplied by the calling method
Step 3: everything in class is indented just like the code in the function, loop, if
statement etc.
Step 4: to make an object of the
class = MyClass ()
Step 5: to call a method in class
c.method1()
c.method2("Testing is a fun")
• Notice that when we call method1 or method2 we don't have to supply the
“self” keyword, that automatically handles for us by the Python runtime.
• Step 6: here is the complete code.
1. Single inheritance
• In single inheritance the child class Acquires the property and can
access all the data members and functional it is defined in parent.
• A child class can also provide in the specific implementation to the
function to the parent class.
Parent
Child
• Syntax:
1. Class DerivedClassName(BaseclassName):
2. <statement-1>
.
.
.
.
<statement -n>
2. Multiple inheritance
• Multiple inheritance it is possible to inherited from more than one
parent class such type of inheritance is called multiple inheritance
• in this case all the attributes and methods of both parent class will
available in this child class
A B
C
Class A: #define your class A
………
Class B: #define your class B
…….
Class C(A, B): #define your class A
………
3. Multilevel inheritance
• Multilevel inheritance we can inherited a derived class from another
derived class this process is known as multilevel inheritance.
Base class
|
Derived class 1
|
Derived class 2
4. Hybrid inheritance
• Hybrid inheritance consisting of multiple types of inheritance is called
hybrid inheritance
5. Hierarchical inheritance
• When more than one derived classes are created from a single base this
type of inheritance is called a Hierarchical inheritance in the following
diagram we have parent class and three child classes
AA
| | |
B C D
Q27. Explain is a relationship and has a relationship
• The member of one class inside a class can access using two concepts
1. by composition (Has-A relation)
2. by inheritance (Is-A relation)
1. Is-A relationship
• in object oriented programming the concept of Is-A is totally based on
inheritance, which can be of two types= class inheritance or interface
inheritance.
• it is just like saying A is a B type of things
• for example, Apple is a fruit car is a vehicle etc.
• Inheritance is unidirectional
• for example, house is a building, but building is not a house
2. Has-A relationship
• Has-A relationship is based on composition
• it means the use of instance variable that references to other object
• for example, Maruti has a engine or house as a bathroom
• Has-A relationship is composition relationship which is productive way of
code reuse.
4th lesson
Q28. Exception in Python
• An exception is also called as runtime error that can hurt the execution of
the program
• Error occurs at run time are known as exception
• An exception is an error that happens or occur during execution of the
program
• When that error occurs, a Python generate an exception that can be
handled which avoid is the normal flow of the program’s instruction
• There are following three types of error occur
1.Compile time error
It occurs at time of compilation due to occur missing of syntax related rules
2.run time error
It occurs during the run time program. it occur due to wrong input
submitted to program by user
3.logical error
It occurs due to wrong logic written in the program
Q36. Tkinter
• Tkinter is the method in GUI
• Out of all the GUI method, Tkinter is the most commonly used method
• It is a standard Python interface to the TK GUI toolkit shipped with Python
• Python with Tkinter is the fastest and easiest way to creating GUI
application
• Creating a GUI by using Tkinter is an easy task
• For creating GUI application using Tkinter
• an easy task, all you need to do this performance from following steps
1.Import Tkinter module
Import Tkinter
Or
from Tkinter import*
2. Create the GUI application main window
3.Add one or more widgets to the GUI application
4. Enter the many event loop (mainloop())to take actions against each
event triggered by user
Q41. Numpy
• Numpy it's Python library for scientific computing in Python
• It is a collection of tools and techniques that can be used to solve
computational mathematical model of problems in science and engineering
• One of these tool is high performance multidimensional array object that is
powerful data structure for efficient computation of array and Matrix
• It is general purpose array processing package
• It is a core library for scientific computing in Python