Python Interview Questions: Python Interview Questions and Answers. Python is an interpreted high-level programming language for general-purpose programming.
Python Interview Questions
Q:- What is Python?

Python is an interpreted, high-level, general-purpose programming language.

Python is a cross-platform programming language, meaning, it runs on multiple platforms like Windows, Mac OS X, Linux etc.

Python was introduced to the world in the year 1991 by Guido van Rossum

Q:- Python Features and Advantages:
  1. Simple and easy to Learn:
    • Python is simple language & easy to learn. write the following code in helloWorld.py file
      print("Hello world!"); //Output Hello world!

      Run the above code - python helloWorld.py

      Congratulations! You just wrote your first program in Python

    • Without having any other programming languages knowledge, you can learn python directly.
  2. Free and Open Source:
    • Python is a open source language, so that anyone can use the python software without purchasing licence.
    • Anyone can read the python source code and can able to do the modification in the source code and also we can redistribute that code to others.
  3. High Level Language:
    • Python is a High Level Programming Language.
    • It is easy to write and maintain programs written in High Level Language.
  4. Python is Interpreted Language:
    • Like PHP, Python is also Interpreted language.
    • Python interpreter is responsible for execution of python applications.
  5. Portable & Platform Independent:
    • The python applications are portable. The applications which are developed by python on one platform are going to execute any platform without making any changes.
    • To achieve the portability feature with respect to the every operating system a separate python software is developed for every version of python.
  6. Embeddable Language:
    • We can embed the python code into other languages such as C,C++, Java and etc..
    • In order to provide the scripting capabilities to other languages we can use the python code in it.
  7. Extensive Support Libraries:
    It provides large standard libraries that include the areas like string operations, Internet, web service tools, operating system interfaces and protocols. Most of the highly used programming tasks are already scripted into it that limits the length of the codes to be written in Python.
  8. Built-in Data Structure:
    It contains lots of data structure like lists, numbers & dictionaries.
Q:- Is python a case sensitive language?
Yes
Q:- What are Namespaces in Python?
A namespace is basically a system to make sure that all the names in a program are unique and can be used without any conflict.
A namespace is a mapping from names to objects. Python implements namespaces as dictionaries
Q:- What are basic Data Types in Python?
Following are the most commonally used basic Data Types in Python:
  1. Number
  2. String
  3. List
  4. Tuple
  5. List
  6. Sets
  7. Dictionary
  8. Boolean
Q:- What is the difference between Lists and Tuples?
Lists Tuples
Lists are mutable, i.e. they can be edited. Tuples are immutable, i.e. they cannot be edited.
Lists are slower than tuples. Tuples are faster than lists.
Syntax: myList = [1,5,10] Syntax: myTuple = (1,5,10)
Q:- What is dictionary in Python?

Dictionary is an unordered collection of elements. Elements in dictionary are stored as key value pair. Dictionary are indexed by keys.

myDictionay = {'name':'FullStackTutorials', 'website':'www.fullstacktutorials.com'}
Q:- What are Modules in Python?
Modules is a set of related functionalities
There are 2 types of Python Modules
  1. Built-in Modules:

    There are several built-in modules in Python, which you can import whenever you like

    Import and use the platform module:

    import platform x = platform.system() print("Platform is: " + x)
  2. Custom Modules:

    You can create your own custom module if required

    To create a module just save the code you want in a file with the file extension .py e.g. - mymodule.py

    def sayHello(name): print("Hello, " + name + " Welcome To Python Interview Questions")

    You can import your custom module whenever you like to use.

    import mymodule mymodule.sayHello("Full Stack Tutorials")
Q:- What is lambda in python?
  1. A lambda function is a small anonymous function.
  2. A lambda function can take any number of arguments, but can only have one expression.
Syntax:
lambda arguments : expression
#Example:

A lambda function that sums argument a and b and print the result:

sumNumbers = lambda a, b : a + b print(sumNumbers(10, 5))
Q:- What is pass in Python?
Pass means, no-operation Python statement, or in other words, it is a placeholder in a compound statement, where there should be a blank left and nothing has to be written there.
Q:- What is iterators?
Iterators is used to iterate over a group of elements, containers, like list :
Q:- What are generators in Python?
The way of implementing iterators are known as generators.
Q:- What is slicing?
A mechanism to select a range of items from sequence types like list, tuple, strings etc. is known as slicing.
Q:- What is docstring in Python?
A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.
Q:- What are Python decorators?
Python decorator is a specific change that we make in Python syntax to alter functions easily.
Q:- What is the difference between list and tuple?
The main difference between lists and a tuples is that -
lists are mutable whereas tuples are immutable.

Q:- What is negative index in Python?

Negative index is used in python to index starting from the last element of the list, tuple or any other container class which supports indexing.

Python sequences can be index in positive and negative numbers. positive index - 0,1,2,3 etc and negative index - -1,-2,-3 etc. -1 refers to the last index, -2 refers to the second last index and so on.

#Example:
lists: >>> array = [0,1,2,3,4,5,6,7,8,9,10] >>> array[-1] //Output 10
Q:- What is the difference between Django, Pyramid, and Flask?

Django:
Django can also used for larger applications. It includes an ORM.

Pyramid:
Pyramid are build for larger applications. It provides flexibility and lets the developer use the right tools for their project. The developer can choose the database, URL structure, templating style and more. Pyramid is heavy configurable.

Flask:
Flask is a "microframework" primarily build for a small application with simpler requirements. In flask, you have to use external libraries. Flask is ready to use.

Q:- How to write comments in Python?

Using # character.

#This is the comment line in Python. print("Python Interview Questions - Comments in Python using #")
Q:- What are docstrings in Python?

Docstrings are not actually comments, but, they are documentation strings. docstrings always written within triple quotes

""" Using docstring as a comment. Python Docstrings details """ print("Python Interview Questions - docstrings in Python")