Top 25 Python Interview Questions and Answers Prepared by Experts


1. What is JSON? How would convert JSON data into Python data?
JSON – stands for JavaScript Object Notation. It is a popular data format for storing data in NoSQL
databases. Generally JSON is built on 2 structures.
  1.  A collection of <name, value> pairs.
  2.  An ordered list of values.
    As Python supports JSON parsers, JSON-based data is actually represented as a dictionary in Python. You can convert json data into python using load() of json module.

2. How are the functions help() and dir() different?
These are the two functions that are accessible from the Python Interpreter. These two functions are used for viewing a consolidated dump of built-in functions.
  • help() – it will display the documentation string. It is used to see the help related to modules, keywords, attributes, etc.
    To view the help related to string datatype, just execute a statement help(str) – it will display the documentation for ‘str, module. ◦ Eg: >>>help(str) or >>>help() – it will open the prompt for help as help>
  • to view the help for a module, help> module module name Inorder to view the documentation of ‘str’ at the help>, type help>modules str
  • to view the help for a keyword, topics, you just need to type, help> “keywords python- keyword” and “topics list”
  • dir() – will display the defined symbols. Eg: >>>dir(str) – will only display the defined symbols. 
3. Which command do you use to exit help window or help command prompt?
quit
When you type quit at the help’s command prompt, python shell prompt will appear by closing the help window automatically. 
4. Does the functions help() and dir() list the names of all the built_in functions and variables? If no, how would you list them?
No. Built-in functions such as max(), min(), filter(), map(), etc is not apparent immediately as they are
available as part of standard module.To view them, we can pass the module ” builtins ” as an argument to “dir()”. It will display the
built-in functions, exceptions, and other objects as a list.>>>dir(__builtins )
[‘ArithmeticError’, ‘AssertionError’, ‘AttributeError’, ……… ] 
5. Explain how Python does Compile-time and Run-time code checking?
Python performs some amount of compile-time checking, but most of the checks such as type, name, etc are postponed until code execution. Consequently, if the Python code references a user -defined function that does not exist, the code will compile successfully. In fact, the code will fail with an exception only when the code execution path references the function which does not exists.
6. Whenever Python exists Why does all the memory is not de-allocated / freed when Python exits?
Whenever Python exits, especially those python modules which are having circular references to other objects or the objects that are referenced from the global namespaces are not always de – allocated/freed/uncollectable.
It is impossible to deallocate those portions of memory that are reserved by the C library.
On exit, because of having its own efficient clean up mechanism, Python would try to deallocate/
destroy every object. 
7. Explain Python’s zip() function.?
zip() function- it will take multiple lists say list1, list2, etc and transform them into a single list of tuples by taking the corresponding elements of the lists that are passed as parameters.
list1 = [‘A’,
‘B’,’C’] and list2 = [10,20,30].
zip(list1, list2) # results in a list of tuples say [(‘A’,10),(‘B’,20),(‘C’,30)]
whenever the given lists are of different lengths, zip stops generating tuples when the first list ends. 
8. Explain Python’s pass by references Vs pass by value . (or) Explain about Python’s parameter passing mechanism?
In Python, by default, all the parameters (arguments) are passed “by reference” to the functions. Thus, if you change the value of the parameter within a function, the change is reflected in the calling function.We can even observe the pass “by value” kind of a behaviour whenever we pass the arguments to functions that are of type say numbers, strings, tuples. This is because of the immutable nature of them. 
9. As Everything in Python is an Object, Explain the characteristics of Python’s Objects.
  • As Python’s Objects are instances of classes, they are created at the time of instantiation. Eg: object-name = class-name(arguments)
  • one or more variables can reference the same object in Python
  • Every object holds unique id and it can be obtained by using id() method. Eg: id(obj-name) will return unique id of the given object.
    every object can be either mutable or immutable based on the type of data they hold.
  •  Whenever an object is not being used in the code, it gets destroyed automatically garbage collected or destroyed
  •  contents of objects can be converted into string representation using a method 
10. Explain how to overload constructors or methods in Python.
Python’s constructor – _init__ () is a first method of a class. Whenever we try to instantiate a object __init__() is automatically invoked by python to initialize members of an object.


Comments

  1. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
    java training in marathahalli | java training in btm layout

    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    selenium training in chennai

    ReplyDelete
  2. Well somehow I got to read lots of articles on your blog. It’s amazing how interesting it is for me to visit you very often.
    python training in pune
    python online training
    python training in OMR

    ReplyDelete

Post a Comment