1. What do you mean by Python?
Python is considered as a high-level, interactive, and object-oriented programming language. It gives high readability to build and understand any applications. It also helps in modeling real-world problems with supporting objects, modules, threads, exception-handling, and memory management.
2. What are the key components of Python?
The key components of Python programming are –
- Object-oriented programming
- General-purpose language
- Dynamically typed
3. Why we need to use Python?
Python is a successful interpreted language that does not need to compile before performing the execution. Here are some benefits that are present –
- Easy-to-learn Python script to emphasize readability.
- It is a dynamic-typed language. So, it does not need to mention the variable type at the time of declaration.
- It allows us to define classes along with composition and inheritance as it is considered as the object-oriented programming language.
- It is used in web-based applications, data modeling, big data analysis, etc.
4. What does PEP 8 stands for?
PEP means a Python Enhancement Proposal. It is considered as an official design document delivering data to the python community, explaining the latest features of Python. In other words, PEP 8 is used to document the style guidelines of this language.
5. What is the process for managing memory in Python?
Memory is managed in Python with the presence of Python Memory Manager. The manager allocates the memory in terms of private heap space. All python objects are stored here and programmers are failed to access these. Also, Python allows us to deliver some core API functions that work on private heap space.
6. What do you mean by pickling and unpickling?
Pickling is a process where a python object hierarchy can transfer into a byte stream or string representation. unpickling is a process where original python objects are retrieved from the string representation.
7. How can we do static analysis in a python application?
To recognize the bugs in the Python project, we can use a static analyzer called PyChecker.
8. What do you mean by slicing in Python?
In order to extract some parts of the string or a list, Python represents a string operator called Slicing. The constructor function,
slice() is used to make a slice object. This method has three parameters – start, stop, and step.
9. What are the different types of functions present in Python?
We can have two basic types of functions in Python –
- User-defined and
- A built-in function such as
10. What do we use PYTHONPATH environment variable?
The working function of PYTHONPATH is similar to PATH. This variable is used to give an instruction interpreter where to locate module files. It has access to the python source library directory.
11. What is the basic difference between list and tuple?
The basic difference between list and tuple is – the list is considered as mutable and the tuple is not. On the other hand, tuples are faster than lists.
Syntax of list:
list_P = [12, ‘Intellipaat’, 14]
Syntax of tuple:
tup_T = (12, ‘Intellipaat’, 14)
12. What is the negative index presentation in Python?
Python allows the sequencing of indexes in both positive and negative numbers. In the case of a positive index, 0 is considered as the first index, 1 is second, and so on. On the other hand, the negative index considers from the last side (-1) as the last, (-2) as the second last, and so on.
13. What is the way to share global variables across modules?
In a single program, we need to create a special module to share a global variable. By importing the config module in all modules of the applications, we can make available global variables within the program.
14. Wat do you mean by Flask and what is the benefit of using it?
Flask is considered as python-based web micro framework having very few dependencies on external libraries. It has integrated support for unit testing. It is known as a built-in development server helping in fast debugging.
15. For return, which keyword is used in Python?
The objective of a function is - receiving inputs and returning some output. The python statement return is used to sending a value back to its caller.
16. What do you mean by self in Python?
Self is a Python keyword that helps to define an object or instance. In Python, the ‘Self’ keyword is used as the first parameter. It allows us to make difference between the methods and attributes of a class.
17. What is inheritance in Python?
As python is an object-oriented programming language, child classes in Python coding can inherit properties of parent classes. This process is known as inheritance. It offers a high reusability feature of code. The class from where attributes are inherited is known as superclass and the class that inherits the superclass is known as a child or derived class.
18. What do you understand by sub(), subn(), and split() functions in Python?
sub(), subn(), and
split() functions are coming under the RegEx ‘
re’ module of Python. These functions help to modify strings.
sub() – It is used to subtract where a regex pattern matches and then the exits substring will alternate with a different string.
subn() – It is similar to sub() but it gives a new string with several replacements.
split() – It helps to split a string into a list.
19. Discuss the map() function in Python.
Map() function has two basic parameters called function and iterable. It considers function as an argument and then uses this function to all elements of an iterable and passed as another argument. Then it returns an object list as a result.
As an instance:
20. Why indentation is important for Python?
Indentation is considered as a part of syntax in Python. It helps to define the scope and extent of the block of codes. It offers better readability of codes which is the main aspect of using Python language.
21. Differentiate between .py and .pyc files in Python?
|This file consists of the source code of a program.
|This file consists of the byte code of a program. Byte code can be generated after compilation of source code.
|During execution, the interpreter involves checking the compiled files. If the file is not found, it checks for .py file.
|If compiled files present, compiles to .pyc file and then virtual machine will execute.
22. What is the process of interpreting in Python?
Python is a language so it is not interpreted or compiled rather than interpretation is a property coming under implementation. The bytecode in Python can be interpreted. Python source code has file name .py extension. Python application compiles the source code as a set of instructions for the virtual machine. The interpreter is considered the implementation of such a virtual machine. .py source code will give byte code i.e. .pyc extension.
23. What do you mean by generators in Python?
Generators are a type of function involve in returning one by one iterable collection of items. With the presence of different methods, generators can create iterators. To return a generator object, it employs the yield keyword instead of return.
24. What is the role of docstring in Python?
To document a specific code segment, the documentation of a string is needed. This docstring involves describing the working principle of each function.
25. Why do we need to use the id() function in Python?
id() is coming under the built-in functions. It passes one parameter and returns a unique identifier depending on the input object. Syntax: id(object)
26. What is the importance of using rstrip() method in Python?
rstrip() function duplicates the string and escapes the characters based on argument value. Syntax: str.rstrip([char sequence/pre>
27. What do you mean by isalpha()?
isalpha() function is a built-in function used for string handling purposes. It will return true if all characters belong to the string otherwise it will return false.
28. CPython difference from Python – Explain.
The core of CPython is developed in C. The interpreter helps to translate the Python-ish code to C language.
29. What is Django?
Django is an open-source web framework used for large applications based on python. It delivers flexibility and allows developers to use the right tools for the specific project. It includes an ORM.
30. What do you mean by Dogpile effect?
When the cache is expired and multiple clients request to access the website at the same time, dogpile effect occurs. We can use a semaphore lock to prevent this effect. When the value expires in the system, the lock is acquired and started to generate new value.
31. What do you mean by %s in Python?
Python language allows formatting value into a string. With the presence of format specifier %s, python can push values into a string.
32. How can we delete a Python file?
We need to use a command -
os.remove (file_name) or os.unlink(file_name)
33. Describe module and package in Python.
Module – Module is a process to structure the program. Each python program itself is called a module. It is used to import objects and attributes.
Package – A package of modules means the folder of the Python Program. A package consists of modules or subfolders.
34. How can we generate random numbers in Python?
In the case of generating random numbers, we need to import a command –
This command will return a random floating value in a range (0, 1).
35. What is the basic difference between Xrange and range?
Xrange is involved to return the Xrange object but range returns the list using the same memory without bothering about range size.
36. What do you mean by *args in Python?
In the function header, we use *args as a parameter. It allows passing N number of elements. But it cannot pass a named argument to the function. *args is used for dynamic arguments.
37. Is there main() function in Python?
In most programming languages,
main() function is the starting of executing program line by line. As Python is an interpreted based language, it sequentially executes lines of code. Python has a main () method but it can be executed whenever we click on it. We are also allowed to override the default function
main () with the presence of if statement.
38. What is the role of “end” in Python?
In Python coding, the print () function is used to print anything in the next line. This function accepts an optional parameter “end”. By default, the value of this parameter is ‘
\n’. Using such a parameter, we can control the end character of a print statement.
39. What is the role of chr() function in Python?
chr() function returns the string with denoting a character. The Unicode of this character is considered as an integer. As an instance, the function
chr(178) will return ‘z’ but
chr(1515) will return the string ‘e’.
40. What does GIL stand for?
GIL stands for (the global interpreter lock) that is supported by Python. GIL is considered as mutex responsible for accessing python objects and synchronize different threads at the time of running bytecode in Python.
41. What is the role of iterator in Python?
Iterators are considered as array-like objects used to allow the movement of the next element. We use the “for” loop as a traversing loop. Python library consists of several iterators. As an instance, a list is considered as an iterator and we are allowed to start a loop over it.
42. What is the role of NumPy in Python?
NumPy is considered a Python package that is used to deal with large data size. It has a powerful N-Dimensional array object and advance features. It also delivers the built-in lists. Because it is compact than the list, more convenient to use, and more efficient.
43. What do you mean by common built-in data types in Python?
Python has several common built-in data types. It does not need to define the data type explicitly at the time of variable declaration. Python has two functions
isinstance() for checking the type of variables.
44. Define break, continue, and pass statements in Python.
Break: The break statement is used to terminate the loop immediately. After this termination, the control will go to the statement after the body of the loop.
Continue: This statement terminates the current iteration of the statement. It also skips the remaining code in the current iteration and control goes to the next iteration.
Pass: Pass is a keyword used to fill up empty blocks and works as an empty statement.
45. What is the role of help() and dir() functions?
The help() function displays the documentation of modules, classes, functions, keywords, etc. An interactive help utility will be launched when the parameter is passed to the help().
The dir() function is used to return a valid list of attributes of an object. For different objects, it works differently. The main object of this function is to produce relevant data.
46. What is the role of PDB commands?
The Python debugger (PDB) is used to debug the Python program. Here are some BDB commands are mentioned:
- List source code (l)
- Step by step debugging (s)
- Add breakpoint (b)
- Print an expression (p)
47. What are globals() function in Python?
The globals() function is involved in returning the current global symbol table in terms of the directory object. Python can manage this symbol table to track all essential information regarding a program. Sign: globals() having no argument.
48. What does Lambda do in Python?
Lambda is considered as an anonymous function involved in accepting several arguments but can have only one expression. It is used for a short period. It can be used in two cases: Assigning Lambda function and wrapping lambda function.
49. What is the basic difference between Lambda and def.?
|Lambda always has one expression function.
|Def can have multiple expressions.
|Lambda makes a function object and returns it.
|It generates a function and designates a name to call.
|It does not have any return statement.
|It can have a return statement.
50. What is the role of Whitespace in Python?
Whitespace shows a character that must be used for spacing and separation. They represent an empty statement as TAB or Space.