QnA
1. What is python?
Python is a high level, interpreted programming language known for its simplicity and readability. Its key features includes dynamic typing, automatic memory management, extensive standard library, and supports multiple programming paradigms like procedural , object oriented, and functional programming.
2. What is interpreted?
An interpreter is a program that directly executes code line by line without converting it to machine language first. It enables dynamic execution and immediate error detection during runtime.
3. What are Python's conditional statements?
Python's conditional statements are used to execute code blocks based on whether a condition is true or false.
4. Break, Continue, Pass statements.
break:
Thebreak
statement is used to exit a loop immediately, stopping all further iterations.continue:
Thecontinue
statement skips the current iteration of the loop and moves to the next iteration.pass:
Thepass
statement is a null operation used as a placeholder where code is syntactically required but no action is needed. It's often used in empty functions, classes, or conditional blocks to avoid syntax errors.
5. How do you define a function in Python?
In Python, a function is defined using the def
keyword, followed by the function name, parentheses ()
for parameters, and a colon :
. The function body is indented and can include a return statement to send back a value.
6. What are *args
and **kwargs
in Python?
In Python, *args
and **kwargs
are used to handle variable numbers of arguments passed to a function.
*args:
This allows you to pass a variable number of positional arguments (arguments that are not named) to a function. It collects these arguments into a tuple.**kwargs:
This allows you to pass a variable number of keyword arguments (arguments that are passed by name) to a function. It collects these arguments into a dictionary where the keys are the argument names and the values are the corresponding values passed.
7. What are exceptions in Python?
Exceptions in Python are runtime errors that disrupt the normal flow of a program. They are handled using try
, except
blocks to gracefully manage errors and prevent crashes.
In Python, exceptions can be handled using try, except, and finally blocks:
- The
try
block contains the code that might raise an exception. - The
except
block catches and handles the exception if one occurs. - The
finally
block contains code that will run no matter what, whether an exception occurs or not.
8. What is the purpose of the raise keyword?
The raise
keyword in Python is used to explicitly trigger an exception. It allows you to raise custom exceptions or re-raise an existing exception within the except
block, enabling better control over error handling.