1. What is Python?

Ans: Python is a high-level programming language developed by Guido Van Rossum in 1991. Python is a general-purpose programming language used in various fields.

  1. What are the features of Python?

Ans: Python supports multiple programming paradigms, including object-oriented, imperative, functional and procedural. The following are the features of Python:

  • Python allows branching and looping as well as modular programming using functions.
  • Python has an effective data handling and storage facility for numeric and textual data.
  •  Python features a dynamic type system and automatic memory management. 
  • Python provides a collection of operators for calculations on list, tuple and dictionary.
  • Python provides a large and integrated collection of tools for data analysis and statistical functions. 
  • The interpreter line interprets Python code byline at a time. This means that there is no need to compile it like other programming languages.
  • It is a platform-independent programming language. Its code easily runs on any platform such as Windows, Linux, Unix, Macintosh etc.
  1. What is Django?

Ans: Django is a Python framework in which we can build websites and web applications. 

  1. What is data science?

Ans: Data science is a technique to handle, manipulate and present data.

  1. What is an interpreter?

Ans: An interpreter is computer software that directly runs commands written in a programming or scripting language. An interpreter does not compile the code.

  1. Why is Python a popular programming language?

Ans: The main reason for the popularity of Python is, We can create a web application, window-based application, games, and mobile application using Python. Also, Python has large support for data science and machine learning. 

  1. What is the difference between a compiler and an interpreter?

Ans: The difference between compiler and interpreter is as follows

CompilerInterpreter
The compiler takes the entire code and translates it into machine code.The interpreter translates code into machine code line by line.
Takes less time for translation.Takes more time to translation.
It generates intermediate code.It does not generate intermediate code.
Debugging is hard using a compiler.Debugging is easy using an interpreter.
Languages like C, C++ use compiler.Languages like Python, ruby use interpreter.
  1. For what purposes Python is used?

Ans: Python is widely used for:

1. Mobile application

2. Web application

3. Games

4. Data science

5. Machine learning

6. Window-based application

  1. What are the advantages of Python?

Ans: The advantages of Python are:

1. Highly readable language.

2. Clean visual layout.

3. Less syntactical structure.

4. Superior string manipulation.

5. Elegant and dynamic typing.

6. Interpreted.

7. Object-oriented.

8. Free open source.

9. High-level programming language.

  1. What is an identity operator in Python?

Ans: It is used to check if the particular element is related to the second element or the sequence which is the same as the membership operator but the value can not be changed.

There are two types of identity operator available

1. is 

2. is not

  1. What is a dictionary in Python and write the syntax of the dictionary?

Ans: Python dictionary is a kind of key-value pair table. Every key should be unique in the dictionary. Dictionaries support unordered pairs of values.

Syntax : 

Dict1 = {key1:value1, key2:value2, key3:value3, … , keyn:valuen}
  1. How to reverse a string using for loop in Python?

Ans: Declare one empty string and store the original string’s last index as the reversed string’s first index. 

Code:

str = str(input(“Enter a string: “)) #Accepting string from the user
print(“The original string is: “, str)

rev = “”
for i in str: # for loop for reversing a string
  rev = i + rev

print(“The reversed string is: “,rev)
  1. What is the use of the join() function in Python?

Ans: The join function in Python is used to join two strings. It provides a flexible way to join strings.

  1. List the built-in types in Python

Ans: There are two built-in types in Python

1. Mutable built-in type

  • List 
  • Set 
  • Dictionary

2. Immutable built-in type

  • String 
  • Tuple
  • Numbers 
  1. Is Python a case sensitive programming language?

Ans: yes, Python is a case sensitive programming language.

  1. What is __init__(self) in Python?

Ans: When we create an object of a class in Python, we need to initialize the attributes of the class using the __init__ method we can initialize the attributes in the class. The __init__(self) is called a constructor in an object-oriented language.

  1. What is a self keyword in Python?

Ans: The self keyword is used to represent an instance of the class. However, the class is the blueprint, self allows access to the data members and methods of each object in Python. It is strongly recommended to call self when we do not have any arguments.

  1. Explain the access specifiers in Python.

Ans: Access specifiers are used to controlling the access of the data members of a class. Using access specifiers, we can avoid direct access to the variables defined in the class.

There are three types of access specifiers in Python.

  • Public:

When we declare the variable directly like self.a = a. By default, every variable declaration is public, which means we can access those variables inside and outside of the class.

  • Private:

When we declare the variable using __(double underscores) like self.__a = a. That means we can access those variables only inside the class, not outside of the class.

  • Protected:

when we declare the variable using _(single underscore) like which means those self._a = a. That means those variable’s scope is only in the class as well as in derived where the base class is extended.

  1. Why does Python not support method overloading?

Ans: The interpreter does not identify the method’s signature feature. We can create methods with the same name, but the latest (last) method is called at the time of calling.

  1. What is the use of the split() function in Python?

Ans: Python split() function takes a string and splits it into the list. 

  1. What is the use of the range function in Python?

Ans: The range function returns the number sequence, which starts with 0 and increments by one by default and stops at a specific number. The range function takes three parameters. Start, stop and step. The start is the optional parameter that specifies the starting number of the range. A stop is a required parameter to specify the ending point of the range. The step is also an optional parameter to specify the incrementation.

  1. What are the membership operators?

Ans: The membership operators are used to check the existence of specific values in the list, tuples or string. These operators return boolean values. If the value is present in the data set then, it will return 1 otherwise 0. There are two types of membership operators

1. in – This will return 1 if the value is present in the data set; otherwise, 0.

2. not in – This will return 1 if the value is not present in the data set; otherwise, 0.

  1. What is the importance of Python function?

Ans: Functions are useful when the program size is too large or complex. Function improves readability since they help split a complex task or procedure into smaller blocks, and each block is called a function. They hide the implementation details from their users and help to reduce the difficulties while debugging a program. Besides, functions are useful when a block of statements has to be written or executed repeatedly. Thus, the function is a standard unit of reuse that improves the readability and debugging of a problem.

  1. Explain slicing in Python.

Ans: Python introduces a new operator, namely, the slice operator. We can slice the data set using it. Also, the Python slice function is there, which works the same as a slice operator. But the execution with the slice operator is fast comparatively.

Example –

str = “Ajay Misal”
print(str[:3])

Output –

Aja

Example –

str = “Ajay Misal”
print(str[:-3])

Output –

Ajay Mi
  1. Explain typecasting in Python.

Ans: Typecasting in Python is the process where we convert one data type into another data type. Python supports two types of typecasting.

1. Implicit typecasting 

In implicit typecasting Python use the interpreter for perform the process.

Example :

a = 3.5
b = ‘Ajay’
print(type(a))
print(type(b))

Output:

<class ‘float’>
<class ‘str’>

2. Explicit typecasting

In explicit type casting we need to convert the different data types manually.

Example:

a = ‘z’
print(list(a))
b = “Ajay”
print(tuple(b))

Output:

[‘z’]
(‘P’, ‘a’, ‘w’, ‘a’, ‘n’)
  1. What is the use of super methods in Python?

Ans: The super method returns the temporary object of the base class. Using that object we can access the base class methods. The super method allows us to avoid the use of the base class name explicitly. We can use the super() method with multiple inheritance.

  1. What does the sorted function do in Python?

Ans: The sorted function returns the data passed to it in a sorted format. This function takes three arguments. 

1. Iterable

2. Key (optional)

3. Reverse (optional)

  1. How to compare two strings in Python?

Ans:

  1. What is the difference between Python 2 and Python 3?

Ans: The difference between Python 2 and Python 3 is as follows.

DifferencePython 2Python 3
Print() functionWithout parentheses, it can print the command.Parentheses is a must; otherwise, it will raise an error.
UnicodeASCII str() types and separate Unicode() but there is no byte type code in it.Unicode (utf-8) and Python 3 has two-byte classesByteBytearray S
ExceptionsIt accepts both new and old notations of syntax.It raises a SyntaxError when we don’t enclose the exception argument in parentheses.
  1. Which Python library is used for machine learning?

Ans: Python has a scikit-learn library that is used for machine learning.

  1. Which Python tool is used for debugging?

And: pylint and pychecker are two tools that are used to debug code.

  1. What is a dictionary?

Ans: A dictionary represents a group of elements arranged in the form of key-value pairs. There are three special objects for dictionary views: keys, values, and items. These objects provide a dynamic view of the dictionary entries, and they change when the dictionary changes. Dictionaries are mutable objects like Lists, and unlike Tuples: this means that they can be changed after creation. In the dictionary, the first element is considered as “key” and the immediate next element is taken as its value. A dictionary maps keys to values. Keys need to be hashable objects, while values can be of any arbitrary type. However, it should be necessary that the keys of a dictionary should be unique.

  1. Explain the pass statement.

Ans: In Python programming, the pass is a null statement. When a pass is executed, nothing is executed. This statement is used when the user has created a code block, but it is not required.

  1. How to convert a list into a tuple?

Ans: To convert a list into a tuple, we can use the tuple() function, which will convert the data stored in the list into a tuple. Ultimately the data becomes immutable.

Example: 

weekdays = [‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’]
listAsSet = set(weekdays)
print(listAsSet)

Output:

{‘c’, ‘i’, ‘d’, ‘h’, ‘g’, ‘b’, ‘a’, ‘f’, ‘e’}
  1. Explain three Python libraries

Ans: Python library is a collection of functions and sub-packages. Functions related to one domain are grouped inside a library, and when the user wants, a particular library can be accessed using import statements in Python.

1. numPy: The most fundamental library around which the scientific computation stack is built is numPy (Numerical Python). It provides an abundance of useful features for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

2. pandas: A Python library designed to work with labelled and relational data is pandas. It is designed for quick and easy data manipulation, aggregation, and visualization. The pandas is a spreadsheet for Python, and it is able to describe the data efficiently. It can do grouping and pivot tables on larger data than most spreadsheet programs.  

3. matplotlib: A Python library tailored to create simple and powerful visualizations with ease is matplotlib. Line plots. Scatter plots, Bar charts and histograms, Pie charts, Stem plots, Contour plots, Quiver plots, Spectrograms etc. Different formatting styles like title, labels, grids, legends etc., are also available in this library.

  1. Explain the nesting of functions.

Ans: The concept of nesting of function is to define one function within another function. Due to simple recursive scope rules, inside function is itself invisible outside of its immediately enclosing function, but can access all local objects (data, functions, types, etc.) of its immediately enclosing function as well as of any functions which, in turn, encloses that function.

  1. What is a tuple?

Ans: A tuple is a sequence of arbitrary Python objects separated by commas. Tuples are similar to lists. But the main difference is that tuples are immutable while lists are mutable. This means that we cannot modify elements of a tuple while changing elements of a list. Thus, tuples are generally used to store data from which we want only to retrieve data but do not require any modification.

  1. Explain the math module in Python.

Ans: The math module is the most important module, which has basic mathematical, logarithmic and trigonometric functions. The different mathematical functions include factorial, floor, ceiling, sqrt etc.; logarithmic functions include log, log10 etc., and trigonometric functions include sin, cos, tan etc. The user can import the math module and can directly use the available functions from this module.

  1. How to create an array in Python?

Ans: The array() function in the array module helps us to create an array in Python. An array can be created using type code and a list containing elements. The type code represents all elements’ nature since the array contains a similar type of elements. Or an array can be created using the array function of the numpy library. We need to pass an argument related to the data type of elements of an array along with the elements. Example: An integer array is created using the “int” argument; a string array is created using the “str” argument; an array of float elements is created using the “float” argument. An array can also be created from an existing array using the view() and copy() command.

  1. Write a Python code to create a multidimensional array (Matrix). Find diagonal elements and the transpose of it. Also, convert it into a single dimensional array.

Ans: 

Code:

import numpy as np
myarray = np.array([[100,200,300],[400,500,600],[700,800,900]])

print(“The matrix is\n”,myarray)
print(“Transpose of matrix is:\n”,myarray.transpose())
print(“Diagonal elements of matrix are:”,myarray.diagonal())
print(“1 Dimensional array of matrix is:”,myarray.flatten())

Output: 

The matrix is
[[100 200 300]
[400 500 600]
[700 800 900]]
Transpose of matrix is:
[[100 400 700]
[200 500 800]
[300 600 900]]
Diagonal elements of matrix are: [100 500 900]
1 Dimensional array of matrix is: [100 200 300 400 500 600 700 800 900]
  1. Accept the number of terms from the user and pass it to the loop and implement the Fibonacci number’s logic in the loop.

Ans: 

Code:

n = int(input(“Enter number of terms: “))
n1, n2 = 0, 1 # first two terms of the fibonacci series
i = 0  #variable for the forloop

if n <= 0:
  print(“Please enter a positive integer”)
elif n == 1:
  print(“Fibonacci sequence upto”,n,”:”)
  print(n1)
else:
  print(“Fibonacci sequence:”)
  for i in range(n):  #forloop upto nth term
      print(n1)
      sum = n1 + n2
      n1 = n2   #Logic for the fibonacci series
      n2 = sum
      i += 1

Output:

Enter number of terms: 10
Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34

Thank you! Our team will contact you shortly.

There was an error while trying to send your request. Please try again.

IIT Workforce will use the information you provide on this form to be in touch with you and to provide updates and marketing.