Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nditah/c8d73ccc9d57b0de084a12a34c2242f2 to your computer and use it in GitHub Desktop.
Save Nditah/c8d73ccc9d57b0de084a12a34c2242f2 to your computer and use it in GitHub Desktop.

Python Interview Questions And Answers

Curated List of Real-time Python Interview Questions. Help fellow developers by contributing to these interview Questions - Create a pull request in Github.

  • What is Python?
    A) Python is an interpreted, high-level, general-purpose programming language. The significant feature of Python Programming Language is its code readability. Python is open source, which makes it free to use and distribute.

  • What are the advantages of using Python?
    A) Python is mainly used for the following:

    1. Extensive Support Libraries like Numpy, Pandas etc.
    2. Dynamically typed Language,
    3. High Level Language,
  • What is an Interpreted Language?
    A) An Interpreted Language is the one which executes most of its instructions directly without the need to compile. Python is a good Example of Interpreted Language.

  • What is PEP 8?
    A) PEP stands for Python Enhancement Proposal. PEP 8 is the style guide for writing elegant python code. It consists of set of rules to enhance the readability of Python code.

  • What is pickling and unpickling?
    A) Pickling or serialization is the process in which Python object hierarchy is converted into byte stream. dumps() function is used to serialize object hierarchy. Unpickling or de-serialization is the process in which the byte stream is converted into Python Object Hierarchy. loads() function is used to deserialize the byte stream.

  • Is Python case sensitive?
    A) Yes. Python is a case sensitive language.

  • How type conversion is handled in Python?
    A) 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() – This function is used to convert to a tuple.

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

    list() – This function is used to convert any data type to a list type.

    dict() – This function is used to convert a tuple of order (key,value) into a dictionary.

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

    complex(real,imag) – This functionconverts real numbers to complex(real,imag) number.

  • What is __ init __?
    A) __ init __ is a constructor function in python. This function is automatically called when a new object / instance is created.

  • What is self in Python?
    A) self represents the instance/object of a class. By using 'self' keyword, we are sending the calling the particular instance of a class.

  • How do you write comments in Python?
    A) Comments in Python starts with #. We can also comment using docstrings (strings enclosed with triple quotes).

  • How will you convert a string to all lowercase in Python?
    A) using lower() function.
    Eg:
    s = 'ABCD'
    print(s.lower())

  • What are the supported data types in Python?
    A) Python has 5 standard data types

    1. Numbers
    2. Strings
    3. List
    4. Tuples
    5. Dictionary
  • What are the Tuples in Python?
    A) Tuples are immutable collection of values enclosed in parenthesis. They can be thought of as read-only lists.

  • What is a list in Python?
    A) List is a mutable collection of values enclosed in square braces. They can be appended with additional values.

  • What is the difference between tuples and lists in Python?
    A) List is enclosed in square braces -[] where as tuples are enclosed in curly braces List is mutable and tuple is immutable.

  • What does ** operator do?
    A) Performs exponential calculation. 2**3 is similar to 2 to the power of 3, i.e. 8.

  • How to check if all the characters in a string are digits?
    A) using isDigit() function.

  • How to initialize an array with zeros?
    A) a = array('i', (0 in range(4)))

  • How to reverse a list?
    A) list.reverse()

  • What is an incomplete function called?
    A) Stub

  • Does python has a compiler?
    A) Yes. Python has a compiler which compiles automatically.'

  • What are dictionaries in Python?
    A) Dictionaries are similar to hashtable type. They contains key-value pairs. Dictionaries usually consists of numbers and strings but can be of any type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment