Topics

Python Interview Questions and Answer For Freshers-Part 1

Python Interview Questions and Answer For Freshers-Part 1

In this blog we will discuss most frequently asked python questions and their answers for freshers. If you are preparing for python developer interview this blog helps you a lot. All the questions and their answer are applicable for both freshers and experienced. 

    Python Interview Questions and Answer For Freshers
    Python Interview Questions and Answer For Freshers

What are the differences between lists and tuples?

Answer: The difference between lists and tuples are as follows. 


 

Lists

Tuples

1

Lists are dynamic in nature.

Tuples are static in nature.

2

Lists are mutable

Tuples are immutable

3

List is iterations is time consuming.

Tuple’s iterations are faster compared to list.

4

Lists consumes more memory.

Tuple consume less memory as compared to list.

5

Lists have several built-in methods.

Tuples does not have many built-in methods.


Python supports what types data types?

Answer: Python supports following data types.

Numbers, String, List, Tuple, Dictionary

For more details on python data types visit: PythonData Types - Python For Beginners (learnpython-coding.blogspot.com)

How to comment on multiple lines in python?

Answer: In Python, the symbol # is used to comment on multiple lines.

How to remove whitespaces from string start and end?

Answer: To remove whitespaces from the string you can use Pythons in-built function strip([str]).This function will return the string after removing the whitespaces if there is no whitespaces in the string it will return the original string.


1.      Difference between Array and list?

Answer: The difference between array and list are as follows.

 

Array

List

1

Array is a collection of homogeneous elements, means same data types.

List is the collections of heterogeneous elements, means different data types. 

2

Array need to declare before the use.

No need to declare list.

3

Array consumes less memory compared to list.

List consumes more memory compared to list.

4

Its hard to modify.

Its easy to modify.


1.      What is __init__ in python?

Answer: This is constructor method in python It can automatically called when new objects gets created and it also allocate the memory to new object automatically.

1.      What is Lambda function in python?

Answer: Lambda function is anonymous function in python that can declare without def() keyword It takes any no of arguments in a single expression. 

1.      What is dictionary in python?

Answer: Dictionary is a built-in data types in python, it contains value in the form of key-value pair.

1.      Explain split () and join () functions in python?

Answer: split () function uses to split a string into list by using delimiter.

               join () function uses to return a new string by joining two strings.

What is type conversion in python? 


Answer: Types conversion is nothing but the type casting, means convert one type of data into other data type.

Python supported following type conversion.

int () – converts any data type into integer type

float () – converts any data type into float type

ord () – converts characters into integer

hex () – converts integers to hexadecimal

oct () – converts integer to octal

tuple () – convert to a tuple.

set () – This function returns the type after converting to set.

list () – convert any data type to a list type.

dict () – convert a tuple of order (key, value) into a dictionary.

str () – Used to convert integer into a string.


Write a program in python to reverse a list ?


Answer: It can be done via several ways , here i am explaining one simple way, write one small function reverse to achieve this ,  The below code will explain it.


Function to reverse the string


What is the difference between .py and .pyc files ?

Answer: The .py files are the python source code files where as the .pyc files contain the bytecode of the files..pyc files are created when the code is imported from some other source, the interpreter converts the source .py files into .pyc files which helps by saving. 

How is memory managed in python ? 

Answer: In Python memory is managed by python private heap Space. All python objects and data structures are located in a private heap. The allocation of heap space for the python objects is done by python's memory manager. Python also has an inbuilt garbage collector which recycles all the unused memory and in this way it can be made be available to the heap space. 

What is namespace in python ?

Answer : A namespace is nothing but naming system to make sure that names are unique to avoid naming conflict. In other words we can say it is the way to implement scope.

What is PYTHONPATH ?

Answer: PYTHONPATH , it is an environment variable which can be set to add additional directories where python will look for modules and libraries. 

What are local variables and global variables in python ?

Answer: Any variable declared inside a function is knows as local variable where as a variable declared out side a function is known as global variable. The global variables can be accessed by any function in the the program. 

Is python case sensitive ? 

Answer: Yes python is case sensitive. 

How Python is interpreted language ? explain

Answer: Python is an interpreted language because it goes through an interpreter, which convert code you write into the language understood by your computer's processor. Python is an interpreted language. This means it uses an interpreter.

You can also check the below blog for more python questions and answers 

Link :Python Interview Questions and Answers Part-2(2023)