Python interview questions and answers

 Python interview questions and answers


14. How can files be deleted in Python?

Ans: To delete a file in Python, you need to import the OS Module. After that, you need to use the os.remove() function.

Example:

1
2
import os
os.remove("xyz.txt")

15. What is pickling and unpickling?

Ans: Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.

16. why python is interpreted language?

An interpreter is basically very different from a compiler.
The interpreter is used mostly for scripting languages like python etc, which directly executes the code (no separate stages for compiling the code and then executing it) by converting it into an intermediate code usually called the byte code. This definitely increases the speed of execution.
This byte code is platform independent which can later be run on different platforms so the code is portable.

17. What is PEP 8?

PEP 8 is defined as a document that helps us to provide the guidelines on how to write the Python code. 

18. What do you mean by Python literals?

Literals can be defined as a data which is given in a variable or constant. Python supports the following literals:

String Literals

String literals are formed by enclosing text in the single or double quotes. For example, string literals are string values.

E.g.:

"Aman", '12345'.

Numeric Literals

Python supports three types of numeric literals integer, float and complex. See the examples.

# Integer literal  
a = 10  
#Float Literal  
b = 12.3   
#Complex Literal   
x = 3.14j  
Boolean Literals

Boolean literals are used to denote boolean values. It contains either True or False.

# Boolean literal  
isboolean = True  

19. What is the namespace in Python?

A namespace is defined as a simple system to control the names in a program


                            NEXT PAGE

Comments