Question 1) – What is Python?
Answer – Python is a high-level, interpreted, general-purpose programming language. Being a general-purpose language, it can be used to build almost any type of application with the right tools/libraries. It uses English keywords frequently, whereas other languages use punctuation, and it has fewer syntactical constructions than other languages.

Question 2) – What are the benefits of using Python?
Answer – Python is a general-purpose programming language that has simple, easy-to-learn syntax which emphasizes readability and therefore reduces the cost of program maintenance.

Question 3) – How Python is interpreted?
Answer – Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.

Question 4) – What are Python decorators?
Answer – A Python decorator is a specific change that we make in Python syntax to alter functions easily.

Question 5) – What is pep 8?
Answer – PEP stands for Python Enhancement Proposal. It is a set of rules that specify how to format Python code for maximum readability.

Question 6) – What is namespace in Python?
Answer – A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.

Question 7) – What are the built-in type does python provides?
Answer – There are mutable and Immutable types of Pythons built-in types Mutable built-in types

  • List
  • Sets
  • Dictionaries

Immutable built-in types

  • Strings
  • Tuples
  • Numbers

Question 8) – What is lambda in Python?
Answer – It is a single expression anonymous function often used as inline function.

Question 9) – Why lambda forms in python does not have statements?
Answer – A lambda form in python does not have statements as it is used to make new function object and then return them at runtime.

Question 10) – In Python what are iterators?
Answer – In Python, iterators are used to iterate a group of elements, containers like list.

Question 11) – What are lists and tuples?
Answer – Lists and Tuples are both sequence data types that can store a collection of objects in Python. The objects stored in both sequences can have different data types. Lists are represented with square brackets ['xyz', 6, 0.19], while tuples are represented with parantheses ('xyz', 5, 0.97).

Question 12) – What are generators in Python?
Answer – The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function.

Question 13) – How can you copy an object in Python?
Answer – To copy an object in Python, you can try copy.copy () or copy.deepcopy() for the general case. You cannot copy all objects but most of them.

Question 14) – What is negative index in Python?
Answer – Python sequences can be index in positive and negative numbers. For positive index, 0 is the first index, 1 is the second index and so forth. For negative index, (-1) is the last index and (-2) is the second last index and so forth.

Question 15) – What is the difference between xrange and range in Python?
Answer – xrange() and range() are quite similar in terms of functionality. They both generate a sequence of integers, with the only difference that range() returns a Python list, whereas, xrange() returns an xrange object.

Question 16) – What is self in Python?
Answer – Self is a keyword in Python used to define an instance or an object of a class. In Python, it is explicity used as the first paramter, unlike in Java where it is optional. It helps in disinguishing between the methods and attributes of a class from its local variables.

Question 17) – Explain how to delete a file in Python?
Answer – By using a command os.remove (filename) or os.unlink(filename)

Question 18) – Mention five benefits of using Python?
Answer –

  • Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc.
  • Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically.
  • Provide easy readability due to the use of square brackets.
  • Easy-to-learn for beginners.
  • Having built-in data types saves programming time and effort from declaring variables.

Question 19) – What is PYTHONPATH in Python?
Answer – PYTHONPATH is an environment variable which you can set to add additional directories where Python will look for modules and packages. This is especially useful in maintaining Python libraries that you do not wish to install in the global default location.

Question 20) – What are local variables and global variables in Python?
Answer – Local variables and global variables in Python are :

Global Variables:

Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.

Local Variables:

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