Python language is the most famous and sought-after skill in the IT industry. According to an IEEE survey, it is the fourth most popular skill. Do you know your all-time favorite companies like Netflix, Instagram, Google, and Spotify use python programming as a core language? Even your local bank you visit uses python. This directs the booming career prospects, which is one of the reasons why people go after Python. You can join a company as a:-

  • Python Developer
  • Software Developer
  • Data Analyst
  • Software Engineer
  • Research Analyst

So, this python tutorial will give you a list of the most frequent questions asked in the job interviews. We would recommend you to keep it in your checklist and mark it whenever you sit for one. If you want to learn Python from scratch you can check out our live sessions in Python by top Industry experts.

What is the difference between lists and tuples in Python?

LIST

TUPLE

  • The elements in the list are written b/w square brackets and separated by a comma.

  list = [123]                  print(list)

  • The elements in the tuple are written b/w round brackets and separated by a comma.

   tuple = (1234)                                   print(tuple)

  • Elements in the list can be changed.

 list.append(5)                                         print(list)                                               [1, 2, 3, 5]

  • Elements in the tuple cannot be changed.

tuple.append(6)                                      …………………………………………………….

 AttributeError                                           <ipython input-19-eca45543f426> in         <module>                                                AttributeError: ‘tuple’ object has no             attribute ‘append’

  • They are relatively slower than tuples because they are allocated in two blocks. One fixed and another variable.
  • They are faster than lists because they are allocated in one fixed block.

What are the different built-in modules in Python?

Python has built-in modules which contain Python code. The code contains function classes or variables. The modules are a .py file containing executable code.

Some of the frequently used built-in modules are:

  • os
  • sys
  • math
  • random
  • data time
  • JSON

What is the difference between local and global variable in Python?

Local Variable

Global Variable

  • Any variable declared inside a function is known as a local variable.
  • Variables declared outside a function or in global space are called global variables.
  • This variable is present in the local space and not in the global space.
  • These variables can be accessed by any function in the program.

Example: local and global variables in python

What do you understand by type conversion in Python?  

Type conversion in Python discusses the conversion of one data type into another. 

int()             It converts any data type into integer type

float()          It converts any data type into float type

ord()            It converts characters into an integer

hex()            It converts integers to hexadecimal

oct()             It converts an integer to the octal

tuple()          It is used to convert to a tuple.

set()             It returns the type after converting to set.

list()             It is used to convert any data type to a list type.

dict()            It is used to convert a tuple of order (key, value) into a dictionary.

str()              It used to convert an integer into a string.

Complex (real,imag)      It converts real numbers to complex(real,imag) number.

What is the difference between array and list in python?

Arrays and lists, in Python, store the data in the same way. But, arrays can hold only a single data type element whereas lists can hold any data type elements.

 Example:

import array as arr
My_Array = arr.array('i', [1,2,3,4])
My_list = [1,'abc',1.20]
print(My_Array)
print(My_list)

array(‘i’, [1,2,3,4])
[1, ‘abc’, 1.2]

What is Lambda function in python?

A lambda function is a single line function that can have any number of arguments but, can have just one expression.

For example x,y are the arguments and x+y is the expression.

a = lambda x,y : x+y
print(a(5,6))

11

What is the use of Python Dictionary?

Dictionary is a built-in data type in Python. It outlines a one-to-one relationship between keys and values. It contains a pair of keys and their corresponding values. The indexing is done on the keys i.e if you want to access the pair value, you will ask for the key.

Let’s take an example: We have made a dictionary in which we have 3 pair of keys and their corresponding values. So to access India you call the corresponding key.

dict = {'Country':'India','Capital':'Delhi', 'PM': 'Modi'}
print (dict["Country"])

India

print (dict["Capital"])

Delhi

print (dict["PM"])

Modi

What Is Object-Oriented Programming?

OOPs or Object Oriented Programming is an approach where we solve a problem in python using objects in our program. There are six important terms in OOPs which are:-

  • Objects– In layman terms an object is an entity that has attributes and behavior. For example, You are an object who has attributes such as height, weight, color, etc. and has certain behaviors such as walking, talking, eating, etc.
  • Class –  A class is a pool of objects. For example, You, Shruti, Akshara and Samarth are all objects so we can define a template or a class “Human” for these objects. The class basically keeps all the objects having common attributes and behaviors.
  • Inheritance – Inheritance is a concept in which one object obtains the attributes and behaviors of the parent object. It creates a parent-child relationship between two classes. For example: If the parent object is “Humans”, then all the child objects will have the attributes of Humans.
  • Polymorphism – Poly means more than one i.e multiple. It refers to the ability of a function or variable to have various forms. For example, in English, the verb take off has different meanings, when used with airplane and clothes. Similarly, len() function in python can be used to calculate the length of a string or a list.
  • Abstraction – An abstraction is a concept in which we represent essential features without including background processes. For example, when you sign up on a portal, you don’t see the background process which happens after you’ve put in your log-in credentials, you only see the essential pages.
  • Encapsulation – Encapsulation is a technique of packaging the data and code in one single unit. The variables of a class are not accessible to other classes. It can only be accessed using the methods of their current class. For example – in a college, a teacher cannot exist without a department.

How to add values to a python array?

We use the following functions to add elements to an array:-

  • append()
  • extend()
  • insert (i,x)

What is the difference between break and continue loop in python? 

  Break Terminates the loop when some condition is met and transfers the control to the next loop or statement,
 Continue It skips some part of a loop when some specific condition is met and the control is then transferred to the beginning of the loop.

LEAVE A REPLY

Please enter your comment!
Please enter your name here