Python Interview Questions

 

1. What are the key features of Python?

Python is one of the most popular programming languages used by data scientists and AIML professionals. This popularity is due to the following key features of Python:

  • Python is easy to learn due to its clear syntax and readability
  • Python is easy to interpret, making debugging easy
  • Python is free and Open-source
  • It can be used across different languages
  • It is an object-oriented language which supports concepts of classes
  • It can be easily integrated with other languages like C++, Java and more

2. What are Keywords in Python?

Keywords in Python are reserved words which are used as identifiers, function name or variable name. They help define the structure and syntax of the language. 

There are a total of 33 keywords in Python 3.7 which can change in the next version, i.e., Python

3. What are Literals in Python and explain about different Literals?

Literals in Python refer to the data that is given in a variable or constant. Python has various kinds of literals including: know more at python online training

  1. String Literals: It is a sequence of characters enclosed in codes. There can be single, double and triple strings based on the number of quotes used. Character literals are single characters surrounded by single or double-quotes. 
  2. Numeric Literals: These are unchangeable kind and belong to three different types – integer, float and complex.
  3. Boolean Literals: They can have either of the two values- True or False which represents ‘1’ and ‘0’ respectively. 
  4. Special Literals: Special literals are sued to classify fields that are not created. It is represented by the value ‘none’.

4. How can you concatenate two tuples?

Solution ->

Let’s say we have two tuples like this ->

tup1 = (1,”a”,True)

tup2 = (4,5,6)

Concatenation of tuples means that we are adding the elements of one tuple at the end of another tuple.

Now, let’s go ahead and concatenate tuple2 with tuple1:

5. What are functions in Python?

Ans: Functions in Python refer to blocks that have organised, and reusable codes to perform single, and related events. Functions are important to create better modularity for applications which reuse high degree of coding. Python has a number of built-in functions like print(). However, it also allows you to create user-defined functions.

6. How to Install Python?

To Install Python, first go to Anaconda.org and click on “Download Anaconda”. Here, you can download the latest version of Python. After Python is installed, it is a pretty straightforward process. The next step is to power up an IDE and start coding in Python. If you wish to learn more about the process, check out this

7. What is Python Used For?

Python is one of the most popular programming languages in the world today. Whether you’re browsing through Google, scrolling through Instagram, watching videos on YouTube, or listening to music on Spotify, all of these applications make use of Python for their key programming requirements. Python is used across various platforms, applications, and services such as web development.

8. How can you initialize a 5*5 numpy array with only zeroes?

Solution ->

We will be using the .zeros() method

9. What is Pandas?

Pandas is an open source python library which has a very rich set of data structures for data based operations. Pandas with it’s cool features fits in every role of data operation, whether it be academics or solving complex business problems. Pandas can deal with a large variety of files and is one of the most important tools to have a grip on.

10. What are dataframes?

A pandas dataframe is a data structure in pandas which is mutable. Pandas has support for heterogeneous data which is arranged across two axes.( rows and columns).

Reading files into pandas:-

1
2
Import pandas as pd
df=p.read_csv(“mydata.csv”)

Here df is a pandas data frame. read_csv() is used to read a comma delimited file as a dataframe in pandas.

11. What is a Pandas Series?

Series is a one dimensional pandas data structure which can data of almost any type. It resembles an excel column. It supports multiple operations and is used for single dimensional data operations.

Creating a series from data:

Code 3.8. A list of all the keywords is provided below:

12. What is pandas groupby?

A pandas groupby is a feature supported by pandas which is used to split and group an object.  Like the sql/mysql/oracle groupby it used to group data by classes, entities which can be further used for aggregation. A dataframe can be grouped by one or more columns. know more at Python training

13. How to create a dataframe from lists?

To create a dataframe from lists ,

1)create an empty dataframe

2)add lists as individuals columns to the list

Q 15) Does Python have a main() function?

A 15) Yes, it does. It is executed automatically whenever we run a Python script. To override this natural flow of things, we can also use the if statement. 

Q 16) What is GIL?

A 16) GIL or the Global Interpreter Lock is a mutex, used to limit access to Python objects. It synchronizes threads and prevents them from running at the same time.

Q 17) Before the use of the ‘in’ operator, which method was used to check the presence of a key in a dictionary?

A 17) The has_key() method

Q 18) How do you change the data type of a list?

A 18) To change a list into a tuple, we use the tuple() function

To change it into a set, we use the set() function

To change it into a dictionary, we use the dict() function

To change it into a string, we use the .join() method

Q 19) What are the key features of Python?

A 19) It is one of the common python interview questions. Python is an open-source, high-level, general-purpose 

Some of its key features are:

  • Interpreted
  • Dynamically-typed
  • Object-oriented
  • English-like syntax

Q 20) Explain memory management in Python.

A 20) In Python, the Python Memory Manager takes care of memory management. It allocates the memory in the form of a private heap space that stores all Python objects and data structures know more at python online course

Comments

Popular posts from this blog

What is Tableau?

SharePoint Interview Questions

Testing Interview Questions