Font size
WorksheetsPython Credential Test
Total questions: 21
Worksheet time: 18mins
What are the different data types available in Python?
float
boolean
str
int, float, complex, str, bool, list, tuple, set, dict, None
Explain the 'if' statement in Python with an example.
Example: x = 10 if x < 5 else 0
Example: x = 10 if x > 5 else 0
Example: x = 5 if x > 10 else 0
Example: x = 0 if x > 5 else 10
Define a function in Python that takes two parameters and returns their sum.
def sum_two(a, b):\n return a + b
def add(a, b): return a + b
def subtract(a, b): return a - b
def sum(a, b): return a * b
How can you read a file in Python?
open('file.txt', 'r').read()
read_file('file.txt')
file.open('file.txt', 'r').read()
open('file.txt').read()
What is the purpose of exception handling in Python?
Exception handling in Python is primarily used for data manipulation
Exception handling in Python is designed to create errors intentionally
Exception handling in Python is used to enhance program performance
The purpose of exception handling in Python is to handle errors or exceptions that occur during the execution of a program.
Explain the concept of modules and packages in Python.
Modules are used for storing data in Python, while packages are used for mathematical calculations.
Modules and packages in Python are the same thing.
Packages in Python are individual files, while modules are collections of files.
Modules in Python are files containing Python code that can be imported and used in other Python files. Packages are a way of organizing modules into directories and subdirectories.
What is the difference between '==' and 'is' operators in Python?
'==' compares values, 'is' compares identities.
'==' compares identities, 'is' compares values.
'==' compares values, 'is' compares memory addresses.
'==' compares memory addresses, 'is' compares values.
How can you handle multiple exceptions in Python?
try: # code that may raise exceptions except (Exception1, Exception2) as e: # handle Exception1 and Exception2 except Exception3 as e: # handle Exception3
try: except Exception1, Exception2 as e: except Exception3 as e: else:
try: except Exception1, Exception2 as e: except Exception3 as e: finally:
try: except Exception1, Exception2 as e: except Exception3 as e:
What is the use of 'finally' block in exception handling?
To handle multiple exceptions in a single block
To skip the execution of code in case of an exception
To execute code that must be run regardless of whether an exception is thrown or not.
To terminate the program immediately upon an exception
How can you create a custom module in Python?
Copy and paste code from existing modules
Use a built-in module without modification
Create a new Python interpreter
Write functions or classes in a separate .py file and import it using 'import' statement
What is the purpose of 'try', 'except', 'else', and 'finally' blocks in Python?
They are used for loop control in Python.
They are used for defining functions in Python.
They are used for data manipulation in Python.
They are used for error handling in Python.
How can you write to a file in Python?
open('filename.txt', 'r').write('content to write').close()
file.write('content to write')
open('filename.txt', 'w').write('content to write').close()
write('filename.txt', 'w').open('content to write').close()
What is the difference between 'for' and 'while' loops in Python?
The 'for' loop is used for a known number of iterations, while the 'while' loop is used for an unknown number of iterations.
The 'for' loop is used for a known number of iterations, while the 'while' loop is used for a specific number of iterations.
The 'for' loop is used for a known number of iterations, while the 'while' loop is used for a known number of iterations.
The 'for' loop is used for an unknown number of iterations, while the 'while' loop is used for a known number of iterations.
Explain the concept of 'pass' statement in Python.
The 'pass' statement in Python is used to print a message to the console.
The 'pass' statement in Python is used to stop the execution of a loop.
The 'pass' statement in Python is used to raise an exception.
The 'pass' statement in Python is used as a placeholder for future code.
How can you import a module in Python?
include module
use module
import math
import module
What is the purpose of '__init__.py' file in a Python package?
To define the directory as a package and initialize the package.
To store package documentation
To define package dependencies
To execute the package code
What is the role of 'as' keyword in Python import statement?
It defines the path where the module is located.
It creates an alias for the imported module or package.
It specifies the version of the module to import.
It restricts the access to specific functions within the module.
Explain the use of 'with' statement in file handling in Python.
The 'with' statement is only applicable to reading files, not writing.
The 'with' statement is used to create a new file in Python.
The 'with' statement simplifies the process of working with files and is considered a best practice in Python programming.
The 'with' statement is deprecated and should not be used.
How can you raise a custom exception in Python?
raise Error('This is a custom exception')
class CustomError()
raise Exception('This is a custom exception')
class CustomException(Exception): pass raise CustomException('This is a custom exception')
21-25.
Answer the questions below after watching the video
What is crucial for adapting in a rapidly changing world according to the first section?
Memorizing historical facts
Continuous learning and adaptation
Ignoring technological advancements
Focusing solely on traditional education
वीडियो में पहले खंड का मुख्य विषय क्या है?
वीडियो संपादन तकनीकें
उन्नत विषयों का परिचय
विस्तृत विवरण
शुरुआती जानकारी और मूल बातें
वीडियो के दूसरे खंड में मुख्य रूप से किस पर ध्यान केंद्रित किया गया है?
शुरुआती जानकारी
उन्नत विषयों और विस्तृत विवरण
वीडियो संपादन
ग्राफिक डिजाइनिंग
वीडियो में विस्तृत विवरण किस खंड में दिया गया है?
चौथा खंड
तीसरा खंड
दूसरा खंड
पहला खंड
According to the second section, what plays a significant role in solving contemporary challenges?
Isolating individual efforts
Sticking to old methods
Avoiding new technologies
Creativity and critical thinking
What is the purpose of '__name__' variable in Python?
It is a reserved keyword in Python
It is used to define variables in Python
It is used to import modules in Python
It helps in identifying the entry point of the program.
