1) What is Python?
Python is a high level, interpreted and object-oriented programming language. It is easy to learn and supports multiple programming patterns.
It is also known as powerful and versatile scripting language.
2) What are the features of Python?
The features of Python are:
- Easy to use.
- Object oriented language.
- Extensible.
- Integrated.
- Interpreted language.
- Cross platform language.
- Expressive language.
3) What are the types of applications developed by Python?
Application developed by python is:
-
- Audio or Video based applications.
Example: TimPlayer etc.
-
- Console based applications.
Example: IPython.
Example: Pocoo, PythonWikiEngines etc.
Example: Gogh, imgSeek etc.
Example: OpenErp, Picalo etc.
4) What are the types of tokens used in Python?
There are following types of tokens used in Python are:
- Keywords.
- Identifiers.
- Literals.
- Operators.
5) Write a simple program in Python to print “PYHTON EXPERT�
Example of Python program:
a= "PYTHON EXPERT"
print a
6) What are the types of keywords used in Python?
The types of keywords used in Python are:
finally |
True |
False |
None |
and |
is |
for |
as |
asset |
def |
else |
not |
return |
lambda |
or |
if |
elif |
class |
import |
try |
7) What are the types of String supported in Python?
There are two types of String supported in Python are:
- Single line String.
- Multi line String.
8) What will be the output of the following code snippet?
x=100
y=200
list=[100,200,300,400,500];
if (x in list):
print "x is in given list"
else:
print "x is not in given list"
if(y not in list):
print "y is not given in list"
else:
print "y is given in list"
OUTPUT:
x is in given list
y is given in list
9) What will be the output of the following code snippet?
x=9>4 and 4>2
print x
y=2>4 or 1<2
print y
z=not(8>4)
print z
OUTPUT:
10) What are the types of “Python Operators�
Types of operator are:
- Arithmetic Operators.
- Assignment Operators.
- Membership Operators.
- Bitwise Operators.
- Relational Operators.
- Logical Operators.
- Identity Operators.
11) What are the types of comments in Python?
There are two types of comment in Python:
Example: # Single Line Comment.
Example: '''Multiple Line Comment.'''
12) What will be the output of the following code snippet?
for i in [10,20,30,40,50]:
if i==30:
pass
print "Pass when value is", i
print i,
OUTPUT:
10 20 Pass when value is 30
30 40 50
13) Write a program in Python to swap two variables?
Example of swapping:
x = input('Enter value of x: ')
y = input('Enter value of y: ')
temp = x
x = y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
14) Write a program in Python to check the number is odd or even?
Example of odd or even number:
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even number".format(num))
else:
print("{0} is Odd number".format(num))
15) Write a program in Python to check the number is positive, negative or zero?
Example:
num = float(input("Enter a number: "))
if num > 0:
print("{0} is a positive number".format(num))
elif num == 0:
print("{0} is zero".format(num))
else:
print("{0} is negative number".format(num))
16) Who is the developer of Python?
Guido van Rossum is the developer of Python.
17) What is dictionary in Python?
Dictionary: It is the collection of components. The components of dictionary are keys and values. Here the values are retrieved by square bracket.
18) How to create a dictionary in Python?
Example:
>>> dictionary={'name':'Atul Jaiswal','id':7014,'dept':'CSE'}
19) Write the following commands used in dictionary?
The following commands used in dictionary are:
-
- Used to create dictionary
dictionary= {'variable':'value'}
-
- Used to check the available key and value pairs in dictionary
dictionary
-
- Used to check the keys available in dictionary
dictionary.keys()
-
- Used to check the values available in dictionary
dictionary.values()
20) What are Tuples?
Tuples: It is the form of collection where the data can be stored. It is also similar to list where data is separated by commas. Tuples are enclosed in parenthesis.
21) How to assign single value to multiple variables in Python?
Example:
a=b=c=7014
print a
print b
print c
22) What are the types of literals available in Python?
The types of literals available in Python are:
- String literals
- Numeric literals
- Boolean literals
- Special literals
- Literal Collections
23) What are the types of Numeric literals available in Pyhton?
Numeric literals are of four types:
- Int(signed integers)
- Long(long integers)
- float(floating point)
- Complex(complex)
24) What is the difference between Object-oriented and Procedure-oriented programming languages?
The difference between Object-oriented and Procedure-oriented programming languages are:
Object-oriented Programming |
Procedural Programming |
The computation is done by using objects. |
It uses a list of instructions to do computation step by step. |
Simulates the real world entity. |
Doesn’t simulate the real world. |
Makes maintenance and development easier. |
Not easy to maintain the codes when project becomes lengthy. |
Example: C++, C#, Java. |
Example: C, Fortran, Pascal. |
25) Which command is used to delete a file in Python?
Command used to delete a file in Pyhton is:
os.remove (filename)
26) What is the use of split function in Python?
split function: This function is used to divide a string into shorter strings by using the defined separator. It also gives the list of words present in the string.
27) What is capitalize() function?
capitalize(): This function is used to capitalize the first character of String.
28) How can you copy an object in Python?
You can copy an object in Python by using:
copy.copy() or
copy.deepcopy()
29) What is docstring in Python?
docstring stands for documentation string. It is a way of documenting functions, modules and classes.
30) What are the types of membership operator used in Python?
The types of membership operator are:
- in operator
- not in operator