You are on page 1of 28

Q1.

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

Q2. Write the features of python


1. Simple and easy to learn
2. interpreted and interactive
3. object oriented
4. platform independent
5. scalable
6. Extendable
7. dynamic
8. GUI programming and databases
9. free and open source

1. Simple and easy to learn


• Program of python is simple language with few keywords simple structure
and its simple and clear define syntax
• Python programming programs are easy to write and execute
2. Interpreted and interactive
• Python is process at runtime by interpreter
• We not need to compile the Python program before executing it
• Python has an option namely, interactive mode which allow interactive
testing and debugging code
3. Object oriented
• Python support object-oriented programming concept that encapsulate
code with object
4. Platform independent
• Python run on wide variety of platform and has the same interface on all
platforms such as windows, Unix, Linux.
5. Scalable
• Python provide a better structure and support for large program that shell
scripting
6. Extendable
• You can add low level modules in Python interpreter
• This module enables programmers to add or customize their tool to be
more efficient
7. Dynamic
• Python provide very high-level dynamic data type and supports dynamic
type checking
• It also supports automatic garbage collection
8. GUI programming and data bases
• Python supports GUI application that can be created and ported to many
libraries and windows systems, such as window Microsoft foundation
classes and X windows system of Unix
9. Free and open source
• Python programming language is developed for developed under OSI
approved, open source licence (OSI) making it freely available at official
website address
Q3. data types in Python in detail
• The type of data values that can stored in and variable is known as data
type
• The data type determines how much memory is allocated to store the data
and which operations can be performed on it.
• The data stored in memory can be of many types and are used to define
the operations possible on them and storage method for each of them
• Data types in Python programming includes
1. Numbers
2. string
3. list
4. double
5. dictionary
6. Boolean
7. none
1.Numbers
• Number data type are stored numeric value
• Numbers can be integers float fraction or even complex number
1.1 Integer: an int data type represents and integer number. an integer
number is number without any decimal point. an integer number is whole
number that can be positive or negative.
1.2 Float: the floor data type represents the floating point number. The
floating point number is a number that contain decimal point. Floating
point number its positive or negative number with fractional part.
1.3Complex: Complex number is a number that is written in the form of a +
bj Here a represents the real part of the number and b represents the
imaginary part of the number.Complex number are written in the form of X
+ yj where X is real part and why is imaginary part
2. String data type
• String is a collection of group of characters.
• String are identified as continuous set of character enclosed in single quite
(' ')or double quiet (" ")
• String in Python supports Unicode character
3. List data type
• List represents sequential data of that programmer wishes to sort, merge
etc.
• Lister most versatile of pythons compound data type
• List is an orderly sequence of items
• The list data type in Python programming it just like an array that can store
a group of elements and we can refer those elements using single name
4. Tuple
• Ordered sequence of items same as list
• Only differences that tuple is immutable
• Tuples are used in write-protect data and are usually faster than list as it
cannot change dynamically
• Tuple data type in program is similar to the least data type which also
contain elements
4. Dictionary data type
• Dictionary Represents a collection of data that associate a unique key with
each value
• Dictionary data type in Python is an unordered collection of key-value pairs
• Items in dictionary are enclosed in curly brackets {} and separated by
comma (,)
5. Boolean
• The simplest building type in Python is bool data type
• It represents the two values, true and false
• Internally the true value is represented as 1 and false is 0
6. None data type
• Python defines a special variable none denoting on Null object
• Python defines a special variable none denoting n object which convenient
to use when variable is available but it's value it's considered as undefined
• None is used to define null variable and object.

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

Q5. Input or output functions


• A Python program needs to interact with user to accomplish desert task or
result, this can be achieved using input output function
• The input() function helps to enter the time at run time by the user and
output function print() is used to display the result of the program on the
screen after execution
• Input means data entered by the user or programmer in the form of
program
• Output means the data comes from computer after processing

Q6. Operator in Python


1. Arithmetical operator
2. comparison operator
3. assignment operator
4. logical operator
5. membership operator
6. identify operator
7. bitwise operator

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

Q7. Accessing string


• Python does not support the character type, these are treated at string of
length one, does also considered a substring
• Square brackets Can be used to access element of string
• We can access individual character using indexing and range of character
using slicing

Q8. List functions and methods


1. Capitalize() :capitalize first letter of string
2. Isdigit() : return to its string contain only digit and false otherwise
3. Isnumeric(): return true if string contain only numeric character and false
otherwise
4. Isspace(): return to its string contain only white space character and false
otherwise
5. Lower (): convert all uppercase letters in lowercase string
6. Upper(): convert all lower case string in uppercase

Q9. What is tuple


• tuple is the collection which is ordered and unchangeable
• In Python, tuples are written with round brackets
• This Python data structure is like a list in Python which is container of
object
• The difference between tuple and list are we cannot change the elements
in tuple once it is a signed where as a list elements can changed
• Tuple you just round brackets where has list use square brackets.
Q10. Advantage of tuple
1. Processing of tuple are faster than list
2. It make the data safe because the tuple are immutable hence it cannot be
changed
3. Generally tuple saree used for different data types and list used for similar
data types
4. Tupels are used for string formatting

Q11. Difference between tuple and list


1. The syntax of tuple shown by parenthesis () whereas, syntax of list shown
by square brackets []
2. tuple has fixed length, List has variable length
3. tuple has immutable nature, List has mutable nature
4. Tuple show structure whereas, list show order
Q12. What is dictionary and how to create dictionary
• Dictionary is a collection which unordered, changeable and indexed
• In Python dictionary are written with curly brackets and they have keys and
values
• Dictionary consists of collection of key value pairs each key value pair maps
the key to its association value
• Creating of dictionary are following
1. Creating a dictionary is a simple at placing item inside {} separated by
comma
2. Each value is separated from its value by colun (:)
3. Empty dictionary without any item is written with just two curly brassers{}
4. Unique with dictionary while value may not be.
Q13What is function
A function is defined as organised block
It is reusable code used to perform single related action
To provide high degree of modularity functions are used
There are two types of functions
1.Build-in functions: the functions that are predefined and organised into Library.
2. User defined function: function that are created by programmer to meet the
requirements

Q14. Anonymous function


• Anonymous functions are functions that are not bond to name it means
why should functions does not have name
• While normal functions are defined using deaf keyword.in Python
Anonymous functions are defined using Lambda the keyword
• That's why Anonymous function are also called lambda function
• lambda Function can take any number of arguments but can only have one
expression
• Langda is created without using def keyword
2nd lesson.
Q15. Modules
• Modules are primarily (.py)files which contain Python programming code
with defining function, classes, variables etc.
• Module is a collection of object in Python such as function classes and so on
• File which containing .py python code is called a module
• The module in Python have .py file extension.
• The name of the module will be the name of the file
• A Python module can be defined as Python program file which contains a
python code including Python functions, classes or variable

Q16. Write steps for creating a module


• Following steps are create modules
1.Create a first file at Python program with extension as.py, this is your
module file where we can write a function which perform some task
2. Create a second file in the same dictionary called main file where we can
import the module to the top of the file and call the function.

Q17. import statement/importing module


• The import statement is used to import a specific module by using its name
• The import statement creates a reference to that module in current
namespace
• We can import the definitions inside a module to another module in Python
• import the definitions inside module
Import p1
Print (p1.add(10,20))
print (p1.sub(20,10))
Q18 Build in module with its list
• Build in modules are generally written in C and bundle with Python
interpreter in pre compiled form
• A building module may a python script containing useful utilities
• Build in module provide numeric and math related function and data types
• Build in module contain following module
1.Math and cmath module
• Python provides to mathematical modules namely math and cmath
• This math module gives us access to hyperbolic, trigonometric functions
for real number
• cmath model allow us to work with mathematical function for complex
number
2. Decimal module
• Decimal number are just the floating point number with fix decimal points
• Decimal model allow us to work with mathematical functions for decimal
values or numbers
3.Fractions module
• A fraction is a number which represents of wool number being divided into
multiple parts
• Python fraction model allow us to manage fractions in Python program
4. Statistic module
• Statistic module provide success to different statistics function
5. Time module
• There is a popular module available in Python namely, time module
• Time modelling Python handle time related task
• To use this functions, we need import the module first like import time.
• Python time model has following functions
Time () this function returns the current time instant
6. Datetime module
• A date in Python is not data type of its own but we can import module
named datetime to work with dates as data object
Q19. Random modules
• Sometimes we want the computer pic a random number in given range or
pick a random element from list etc.
• The random model provide function to perform this type of operations.
This function is not accessible directly so we need import random module
and then we need to call this function using random static object

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.

Q23. What is class variable


• Class variable are defined within the class constructor, Because they are
owned by the class itself
• Class variables are shared by all instance of the class
• Class variables are defined within a class but outside any of the class's
methods.
• Class variables are not used as frequently as instance variables are.
• Data member − A class variable or instance variable that holds data
associated with a class and its objects.

Q24. Explain class methods in Python.


• There are three types of methods in Python instance method, static
methods, and class methods.
1. Instance method:
• instance methods are the most common type of methods in Python these
are so called because they can access unique data of their instance
• if you have two objects each created from a car classes, then they each
may have different properties
• they may have different colors, engine size, seat and so on.
• instants methods must have self as a parameter, but you don't need to
pass this in every time
• self is another Python special term.
2. Static methods:
• static methods are methods that are related to a class in some way, but
don't need to access any class specific data
• static methods are defined without self as an argument and don't need
to instantiate an instance they can be called directly on the class itself.
• Static methods are defined without self as an argument and they can be
called directly on the class itself
3. Class methods:
• class methods know about their class
• they can't access specific instance data but they can call other static
methods
• Class methods don't need self as argument but they need a parameter
called cls, this stands for class and like self, get automatically pass in by the
python.
• Class methods are created using the @classmethod decorator.
• Class methods can manipulate the class itself, which is useful when you
are working on larger more complex project.

Q25. Differentiate between Deep and shallow copy


• Deep copy, copies an object into another
• this means if you make a change to a copy of the object, it want affected
the original object
• In Python we use the function deepcopy() for this.
• Shallow copy copies one object reference to another
• that means if you make a change to a copy of an object, it will be affect
the original object in python we use the function copy ()
Q26. Explain types of inheritance in Python.
types of inheritance
1.Single inheritance
2.multiple inheritance
3.multilevel inheritance
4.hybrid inheritance
5.Hieracrchical inheritance

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

Q29. Exception handling with their blocks


• The exception handling is the process that provides of way to handle
exceptions that occurs at run time
• The exception handle is done by writing exception handlers in the program
• exception handlers are the blocks that executes when some exception
occur at run time
• There are three blocks that are used in exception handling process namely
try, except, final
1.try block: a set of statement that may cause error during runtime, are to
be written in the try block
2. Except block: it is written to display the execution detail to the user
when certain exception occurs in the program. The expect block executes
only when a certain type exception occur in the execution of statement
written in the try block
3. Finally block: this is the last block written while writing, an exception
handling in the program which indicate is the set of statements that are
used to clean up the resource used by the program

Q30. What is built-in exception


• Python has many built in exceptions which forces your program to output
and error when something in it goes wrong
• List of built-in exception
1. Arithmetic error: base class for all errors that occurs for numeric
calculation
2. Exception: base class for all exceptions
3. Import error: raised when an import statement fails
4. Index error: raised when an index is not found in sequence

Q31. Raise statement


• We can raise and existing exception by using raise keyword
• So just simplify raise keyword and then the name of the execution
• The raise statement allows the programmer to force a specified exception
to occur
• Here, exception is a type of exception and argument is a value for the
exception argument. this argument is optional. the exception argument is
none if does not supply any argument. the argument trackback is also
optional. if this is used then the trash back object is used for the exception.
this rarely used in programming
Q32. What is custom or user defined exception
• User can create his own error using exception class
• Creating your own exception class are user defined exception are known as
custom exception
• Python throw error and exceptions when there is a code going wrong which
may cause program to stop.
• Python allow you to create your own exception by driving classes from the
standard build-in exception
• Here is an example related to runtime error here is a class created that
subclassed from runtime error. this is useful when you need to display
more specific information when an exception is caused.
Q33. Assert statement
• Assert is a Boolean expression to self check and assumption about the
internal state of function or object
• It true nothing happens, otherwise execution halt and error is thrown
• For example, while writing a division function you are confident the divisor
should not buy zero you, are assert divisor is not equal to zero
• Assertions are carried out by the assert statement
• Programmer of one place a social at the start of the function to check the
valid input and after the function called to check the valid output
5th lesson
Q34. GUI
• GUI is a graphical user interface
• It is an iterative environment to take response from the users on various
situations like forms, document, test etc.
• It provides user a good iterative screen then traditional command line
interface
• According to the definition of GUI, it is an interface, which through user
communicates with the electronic devices like computer, mobiles and other
devices
• This interface utilize symbol, icon, menu and graphics to display
information
• GUI representation can be managed and manipulated by pointing device
such as mouse in computer and finger in on screen
Q35 . Write the justification for need of GUI frameworks
• They need for the GUI framework is justified because the in first computer
the text interface is created by keyboard and the command line given by
the keyboard to initiate responses. For that a computer needs exact
spelling which creates difficulties and appropriate interface

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

Q37. Tkinter widgets


1. Button
The button widgets is used to display buttons in your application
2. check button
The check button widgets is used to display a number of options as check
box. we can select multiple options at a time
3. frame
The frame widgets is used to container widgets to organised other widget
4. label
The label widgets is used to provide single line caption for other widget
5. list box
The listbox widget is used to provide list for option to a user
6. menu botton
The menu button widgets is used to display a menus in application
7. message
The message used to display multiline text field for accepting value from
user
8. radio button
The radio button is used to display a number of options as a radio button.
the user can select only one option at a time
9. text
The text will get is used to display text in multiple line
10.scrollbar
The scrollbar widgets is used to add scrolling capability to various widgets
such as list box
Q38. List out geometric management method
• The pack (): this method manage the geometry of widget in block
• The grid (): this method organised widget in tabular structure
• The place (): this method organised the widget to place them in specific
position

Q39. Write methods for geometric management of tkinter


• When widgets are construct in tkinter, we can specify how they should be
configured
• The GUI script passes arguments to the label class constructor
1.The first is a parent will get object which we want the new label to be
attached to
• Here, None means attached the new label to the default top level window
of this program
• Later we will pass real widget in this position to attach our labels to the
other container object
2.The second is configuration option for the label, passes as a keyboard
argument the text option specify a text string to appear as a label message to
other container object
• Most widget constructors accept multiple keywords argument for
specifying a variety of options like colour, sizes, call back handers and so on
3. The example of tkinter,
From tkinter import lable. #get a widget object
Widget=lable (None,text='Hello'). #make the instance
Widget.pack(). #arrange it
Widget.mainloop(). #start event loop
Q40. What is frame, button, label
1. Frame
• Frame is used as container in the tkinter for grouping and organising the
widgets
• Syntax
frame_widget=tk.frame (widget option=placesholder)
• Option for frame
1. Background
2. border
3. height
4. highlight background
5. highlight colour
6. highlight thickness
2. Button
• Button Widget has a property for switching on and off
• Syntax
button_widget=tk.button(widget option=placesholder)
• Option for button
1. Background
2. border
3. forground
4. font
5. height
6. image
7. underline
3. Label
• Label is used to create single line widget like text, image etc
• Label widgets display the text with the default system text colour and
default system text background colour
• You can control label text and background colour using the forground and
background parameters
• Syntax
Lable_widget=tk.lable(widget option=placesholder)
• Option for label
1. Anchor
2. background
3. border
4. cursor
5. font
6. Forground
7. height
8. image
9. text
10. underline
6th lesson

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

Q42. Pandas with Advantages and features of pandas


• Pandas is one of the most widely used Python library in data science
• It provide high performance, easy to use structure and data analysis tools.
• Pandas provide in memory to the table object call data frame, it is like
spreadsheet with column names and row labels
• Panda is open source providing high performance easy to use structure and
data analysis to for Python programming language
• Advantages of pandas
1. An extensive set of feature
2. Less writing more work done
3. excellent data representation
4. make the data flexible and customisable
• Feature of pandas
1. Fast and efficient data frame object for data manipulation
2. Tool for reading and writing data between in-memory data structure
3. Intelligent data alignment and integrate handling of missing data
4. Flexible re-shaping
5. Column can inserted and delete from data Structure for size mutability
6. high performance merging and joining of data sets

Q43. What is scikit-learn


• scikit-learn is pronounced as Sy-kit learn sci stand for science
• scikit-learn provides a range of supervised and unsupervised learning
algorithm through a consistent interface in Python
• It is a probably most useful library for machine learning in Python
• It is on numpy, scipy and matplotlib, this contents a lot of efficient tool for
machine learning and statistical modeling.
• This library build upon the scipy (scientific python) that must be installed
before you can use scikit learn
• It includes
1. Numpy
2. Scipy
3. Matplotlib
4. Ipython
5. Sympy
6. Pandas
• Features of scikit learn
1. It is simple and efficient tool for data mining and data analysis
2. It provide various features like classification, regression, and clustering
algorithm which including support vector machine, random forest, k-
means etc

You might also like