Python Short Questions


Python Short Questions 


How you can execute python program on command prompt?
Change  your working directory at c:/python and then type python
program –name .py

Define List.
List is a mutable data structure that can have elements that belong to the different data structure.

Define Tuple.
It is a sequence of immutable objects i.e , values of data items can’t be changed.

Give the syntax for a function definition.
def function_name (variable1 , variable2, …..)
                                    statement1…….statement n
                                    return (expression)

Name different types of arguments while defining a function.
a.     Required arguments
b.     Keyword arguments
c.      Default arguments
d.     Variable length arguments

What are global variables?
Variables defined in the main body of a program are called global variables and are visible throughout the program file.

 What are global variables?What are local variables?
A variable which is defined within a function is called local variable. A local variable can be accessed from the point of its definition until the end of function in which it is defined.

 What is an exception?
An exception occurs because of some mistake in program that system cannot detect before executing the code as there is nothing wrong in terms of syntax, but leads to a situation during the program execution that system cannot handle. These errors disrupt the flow of program at run-time by terminating the execution at the point of occurrence of error.                       

What is regular expression?                       
It is a special sequence of characters that helps to match or find strings in another string.

 What is data encapsulation?
Organizing the data and methods into a structure that data access by a function or method that is not specified in the class.

Syntax of if statement.
if(condition):
            set of statements….          

Explain try except clause.
It is used for exception handling. Try block consists of statements that have potential to raise exceptions and the except block describes the action to be taken when an exception is raised.

Describe break and continue statement.
Break: - it is used to terminate the execution of the nearest enclosing loop in which it appears.
Continue:- like the break statement , the continue statement can only appear in the body of a loop. When the compiler encounters a continue statement then the rest of the body of the statements in the loop are skipped and the control is transferred to the loop-continuation portion of the nearest loop enclosing.


What is open() method?
It is used to create a file object that will be used to invoke methods associated with it.

What is close() method?
It is used to close the file object.

Define class
It is a user defined prototype for an object that defines a set of attributes and methods that are accessed via dot(.) notation.

Give syntax for defining a class in python.
Class class_name:
            St-1
            St-2
            ---
            ----
            St-n

Define polymorphism.
It is the property that provides ability to process data in more than one form

Define inheritance.
Technique of creating a new class from existing class is called inheritance.

Define sets.
.A set is a mutable and unordered collection of data items.

How a set is created?
It is created by placing all elements inside curly brackets{} , separated by comma(,) or using a built in function set().

Give few applications of python.
a.     Web development
b.     3 d software
c.      Gui based desktop applications
d.     Image processing

What is Unicode?
It is a standard way of writing international text. Python allows to specify Unicode text by prefixing the string with letter u or U.

Syntax of  format() function
Format(value, format-specifier)

Define variables
These are reserved memory locations that store values. Each value is given an appropriate name.

Define identifiers.
These are the names given to the something that can be a variable, function, class module or other object.

What is function.
A function is a block of organized and reusable program code that performs a single and well defined task.

What is recursive function.
The function that call itself to solve similar version of task is called recursive function.

What is module?
It is a pre-written piece of code that are used to perform common task .

What is multiple inheritance?
When a derived class inherits features from more than one base classes, it is called multiple inheritance.

Define multilevel inheritance.
The technique of deriving a class from an already derived class is called multi-level inheritance.

Define multipath inheritance.

Deriving a class from other derived classes that are in turn derived from the same base class is called multi-path inheritance.