NEW
Font size
WorksheetsPython Class 8 Assessment
Total questions: 10
Worksheet time: 5mins
What are the different data types in Python?
The different data types in Python include: int, float, complex, str, list, tuple, dict, set, bool, bytes, bytearray, range, None
int, float, str, bool, list
integer, decimal, string, boolean, array
number, text, boolean, array, dictionary
How do you declare a variable in Python?
value = variable_name
variable_name = value
value variable_name
variable_name == value
What is the syntax for an if-else statement in Python?
if condition: # code to be executed if the condition is true else: # code to be executed if the condition is false
if condition: # code to be executed if the condition is true else: # code to be executed if the condition is true
if condition: # code to be executed if the condition is true else: # code to be executed if the condition is false
if condition: # code to be executed if the condition is false else: # code to be executed if the condition is true
What is the purpose of a function in Python?
To perform a specific task or set of tasks, and allow for code reusability and modularity.
To slow down the execution of the program
To make the code more complicated and difficult to understand
To make the code less organized and harder to maintain
How do you import a module in Python?
load moduleName
use moduleName
import moduleName
include moduleName
What is the difference between read() and readline() methods in file handling?
The read() method reads one line at a time, while the readline() method reads the entire file at once.
The read() method reads the entire file at once, while the readline() method reads one line at a time.
The read() method reads the entire file at once, while the readline() method reads the entire file at once.
The read() method reads one line at a time, while the readline() method reads one character at a time.
What is the use of the 'with' statement in file handling?
To open the file in read-only mode
To create a new file
To ensure proper file handling and automatic closing of the file
To delete the file after use
What is the difference between 'w' and 'a' modes in file handling?
The 'w' mode is for writing and the 'a' mode is for appending.
The 'w' mode is for appending and the 'a' mode is for writing
The 'w' mode is for reading and the 'a' mode is for writing
The 'w' mode is for reading and the 'a' mode is for appending
How do you write to a file in Python?
open('filename.txt', 'a').write('content')
open('filename.txt', 'r').write('content')
open('filename.txt', 'w').write('content')
write('filename.txt', 'w').open('content')
How do you define a class in Python?
def ClassName():
class ClassName:
ClassName = class():
ClassName = def():
