Python Interview Questions | Python Viva Questions

In this article python interview questions we give the information about python interview questions for freshers, python viva questions and python basic interview questions.

Python Interview Questions:

Ques-1 What is Python?

Ans-Python was created by Guido van Rossum, and was released in 1991.

It is a general-purpose computer programming language. It is a high-level, object-oriented programming language that can run concurrently on various platforms such as Windows, Linux, Unix, and Macintosh. Its high-level built-in data structures, combined with dynamic typing and dynamic binding. It is widely used in data science, machine learning and artificial intelligence domains.

It is easy to learn and requires less code to develop the applicationIt is widely used for:

  • Web development (server-side)
  • Software development
  • Mathematics
  • System scripting

Ques-2 Explain Python Functions?

Ans- A function is a section of a program or a block of code that is written once and can be executed whenever it is needed in the program. A function is a block of self-contained statements that has a valid name, parameters list, and body. Modular tasks make programming more functional and modular for performing tasks. Python provides many built-in functions to accomplish tasks and allows the user to create new functions as well.

There are three types of functions-

  • Built-In Functions– copy(), len(), count() are some built-in functions.
  • User-defined Functions – Such functions which are defined by the user are called user-defined functions.
  • Anonymous functions – These functions are also known as lambda functions as they are not declared with the standard def keyword.

Ques-3 What is tuple in Python?

Ans–A tuple is a built-in data collection type. This allows us to sequence the values ​​in a sequence. It is immutable, so there is no change in the original data. It uses ( ) brackets instead of [ ] square brackets to create a tuple. We cannot remove any element but can find in tuple. We can use indexing to get the element. It also allows elements to be traversed in reverse order using negative indexing. tuple supports various methods like max(), sum(), sorted(), Len() etc.

 Ques-4 How is memory managed in Python?

Ans- Memory is managed in python in the following ways:

  • Memory management in python is managed by Python private heap space. All python objects and data structures are kept in a private heap. The programmer does not have access to this private heap. Instead the python interpreter takes care of it.
  • Allocation of heap space for Python objects is done by Python’s memory manger. The core API provides access to some tools for programmers to code.
  • Python also has an inbuilt garbage collector, which recycles all unused memory and makes it available in heap space.

Ques-5 What are the rules for a local and global variable in Python?

Ans- Global Variables:

  • Variables declared outside a function or in the global space are called global variables.
  • If a variable is ever assigned a new value inside the function, then the variable is implicitly local, and we need to explicitly declare it as ‘global’. To make a variable globally, we need to declare it using the global keyword.
  • Global variables are accessible anywhere in the program, and any function can access and modify its value.

Local Variables

Any variable declared inside a function is known as local variable. This variable exists in local space and not in global space.

If a variable is assigned a new value anywhere in the body of a function, it is considered local.

Local variables are available only within local body.

Python Interview Questions:

Ques-6 What is slicing in Python?

Ans– Slicing is a mechanism used to slice a range of items from sequence types such as list, tuple, and string. It is beneficial and easy to get elements from a range using slicing. It requires a : (colon) that separates the start and end indexes of the field.

All data collection types List or Tupple allow us to use slicing to fetch elements. Although we can get the elements by specifying an index, we get only one element whereas by using sylicing we can get a group of elements.

Ques-7 What is the usage of help() and dir() function in Python?

Ans- Help() and dir() both functions are accessible from python interpreter and are used to view consolidated dump of built-in functions.

Help() function: The help() function is used to display the documentation string and also allows us to view help related to modules, keywords, and attributes.

Dir() function: The dir() function is used to display the defined symbols

Ques-8 What is PEP 8?

Ans- PEP 8 stands for Python Enhancement Proposal, it can be defined as a document which helps us to provide guidelines on how to write python code. It is basically a set of rules that specify how to specify python code for maximum readability. It was written in 2001 by Guido van Rossum, Barry Warsaw and Nick Coghlan.

Python Interview Questions:

Ques-9 What advantages do NumPy arrays offer over (nested) Python lists?

Ans- List of pythons are efficient general-purpose containers. They make it easy to perform efficient insertion, deletion, appending, concatenation, Python’s list comprehensions.

They do not support “vectorized” operations such as addition and multiplication per element, and they can contain different types of objects, which means that python must store type information for each element, and when the type The dispatching code must execute while working on each element.

NumPy is not only more effecient it is also more convenient. We get a lot of vector and matrix operations for free, which sometimes allow one to avoid unnecessary work. And they are also implemented efficiently.

NumPy is araay fast and we get a lot with NumPy FFTs, convolutions, fast searching, basic statistics, linear algebra, histograms etc.

Ques-10 What are the applications of Python?

Ans- Python is used in various software domains,

  • Image processing and graphic design applications
  • Enterprise and business applications development
  • Operating systems
  • GUI-based desktop applications
  • Web and Internet Development
  • Games
  • Scientific and computational applications
  • Language development

Related Link:

Some More: DBMS/ WT/ DMDW

Santosh Nalawade

Work as Assistant Professor and Web Developer.

Leave a Reply

Your email address will not be published. Required fields are marked *