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.
databases. Generally JSON is built on 2 structures.
- A collection of <name, value> pairs.
- 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.
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’, ……… ]
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.
Comments
Post a Comment