python-viva
python-viva
What is Python?
• Python is a widely-used general-purpose, high-level,interpreted
programming language. It was created by Guido van Rossum in 1980.
What are the benefits of using Python language
The following are the benefits of using Python language:
• Object-Oriented Language
• High-Level Language
• Dynamically Typed language
• Extensive support for Machine Learning Libraries
• Presence of third-party modules
• Open source and community development
• Portable and Interactive
• Portable across Operating systems
Is Python a compiled language or an
interpreted language?
Python is primarily an interpreted language, meaning it executes code
line by line at runtime using an interpreter. It does have a compilation
step where the source code is converted to bytecode, which is then
executed by the Python Virtual Machine (PVM). This allows for
flexibility and ease of debugging, but it may result in slower execution
compared to fully compiled languages.
What does the ‘#’ symbol do in Python?
‘#’ is used to comment on everything that comes after on the line.
5//2 = 2
5/2 = 2.5
How is Exceptional handling done in Python?
• There are 3 main keywords i.e. try, except, and finally which are used
to catch exceptions and handle the recovering mechanism
accordingly. Try is the block of a code that is monitored for errors.
Except block gets executed when an error occurs.
• The beauty of the final block is to execute the code after trying for an
error. This block gets executed irrespective of whether an error
occurred or not. Finally, block is used to do the required cleanup
activities of objects/variables
Difference between for loop and while loop in
Python
The “for” Loop is generally used to iterate through the elements of
various collection types such as List, Tuple, Set, and Dictionary.
Developers use a “for” loop where they have both the conditions start
and the end. Whereas, the “while” loop is the actual looping feature
that is used in any other programming language. Programmers use a
Python while loop where they just have the end conditions.
What are *args and **kwargs?
To pass a variable number of arguments to a function in Python, use
the special syntax *args and **kwargs in the function specification.
Both are to send a variable-length argument list. The syntax *args is
used to pass a non-keyworded, variable-length argument list.