wayground logo

Lembar Kerja Gratis yang Dapat Dicetak

BARU

Ukuran huruf

S
M
L
XL
Lembar kerja

Exploring Python Fundamentals

Total soal: 60

Worksheet time: 30mins

Nama
Kelas
Tanggal
1.

How do you read input from the user in Python?

a)

Use the 'fetch()' function to obtain user input.

b)

Use the 'read()' function to get user input.

c)

Use the 'input()' function to read input from the user.

d)

Use the 'scan()' function to read input from the user.

2.

What is the purpose of the 'print()' function in Python?

a)

To create a new variable in memory.

b)

To execute a loop in a program.

c)

To output data to the console.

d)

To read data from a file.

3.

Explain the difference between 'if', 'elif', and 'else' statements.

a)

'if' and 'else' are the same, while 'elif' is used for functions.

b)

'if' checks a condition, 'elif' checks additional conditions, and 'else' executes if all previous conditions are false.

c)

'if' always executes, 'elif' is for error handling, and 'else' checks for true conditions.

d)

'if' is used for loops, 'elif' is a synonym for 'if', and 'else' is optional.

4.

How does a 'for' loop differ from a 'while' loop in Python?

a)

A 'for' loop is used for iterating over a sequence, while a 'while' loop continues based on a condition.

b)

A 'for' loop requires a condition to start, while a 'while' loop does not need any condition.

c)

A 'for' loop is only used for numeric ranges, while a 'while' loop can iterate over any data type.

d)

A 'for' loop runs indefinitely, while a 'while' loop stops after a set number of iterations.

5.

What does the 'break' statement do in a loop?

a)

The 'break' statement exits a loop.

b)

The 'break' statement restarts the loop from the beginning.

c)

The 'break' statement skips the current iteration of a loop.

d)

The 'break' statement pauses a loop.

6.

How can you skip an iteration in a loop using 'continue'?

a)

Placing 'continue' outside any loop will skip iterations.

b)

You can use 'break' to skip an iteration in a loop.

c)

Using 'continue' without any condition will always skip the iteration.

d)

You can skip an iteration in a loop using 'continue' by placing it inside a conditional statement that determines when to skip.

7.

What is the purpose of the 'pass' statement in Python?

a)

The 'pass' statement is used to define a function.

b)

The 'pass' statement terminates a loop immediately.

c)

The 'pass' statement is used for error handling in Python.

d)

The 'pass' statement serves as a placeholder in Python.

8.

How do you define a function in Python?

a)

def function_name(parameters):

b)

create function_name(parameters)

c)

function_name(parameters) =>

d)

function_name: parameters()

9.

What is the difference between parameters and return values in functions?

a)

Parameters are used to define the function; return values are used to call the function.

b)

Parameters are outputs from a function; return values are inputs to a function.

c)

Parameters are inputs to a function; return values are outputs from a function.

d)

Parameters are optional values; return values are mandatory values.

10.

What is variable scope and how does it work in Python?

a)

There are only two types of variable scope in Python.

b)

Variable scope only applies to global variables.

c)

Variable scope is irrelevant in Python programming.

d)

Variable scope in Python defines where a variable can be accessed and its lifetime, with four types: local, enclosing, global, and built-in.

11.

Can you explain the concept of recursion with an example?

a)

Recursion is a method of sorting data in arrays.

b)

Recursion is a technique used to optimize database queries.

c)

Recursion is a way to iterate through a list using loops.

d)

Recursion is a function that calls itself to solve smaller instances of a problem.

12.

What are some common string operations in Python?

a)

Sorting, merging, trimming

b)

Encoding, decoding, hashing

c)

Parsing, validating, formatting

d)

Concatenation, repetition, slicing, finding, replacing, uppercasing, and property checks.

13.

How do you create and manipulate lists in Python?

a)

You cannot sort a list in Python.

b)

Lists can only be manipulated using the list() function.

c)

To create a list in Python, use square brackets. To manipulate, use methods like append(), remove(), and sort().

d)

Use curly braces to create a list.

14.

What is list slicing and how is it used?

a)

List slicing allows you to add elements to the end of a list.

b)

List slicing is a method to extract a portion of a list using the syntax list[start:end:step].

c)

List slicing is used to merge two lists into one.

d)

List slicing is a method to sort a list in ascending order.

15.

What is a tuple and how does it differ from a list?

a)

A tuple is a mutable unordered collection, while a list is an immutable ordered collection.

b)

A tuple can be modified after creation, while a list cannot.

c)

A tuple is a collection of unique elements, while a list can contain duplicates.

d)

A tuple is an immutable ordered collection, while a list is a mutable ordered collection.

16.

How do sets ensure uniqueness of elements in Python?

a)

Sets use a list structure to store elements.

b)

Sets require elements to be of the same data type.

c)

Sets ensure uniqueness by using a hash table to prevent duplicate elements.

d)

Sets allow duplicate elements by default.

17.

What are dictionaries and how do you create key-value pairs?

a)

Dictionaries are only used for storing lists.

b)

Dictionaries can only contain numeric keys.

c)

Key-value pairs are created using square brackets, e.g., ['key', 'value'].

d)

Dictionaries are collections of key-value pairs created using curly braces, e.g., {'key': 'value'}.

18.

How do you read from a file in Python?

a)

Use read('filename') to access the file directly.

b)

Use open('filename', 'r') to open the file and read its contents.

c)

Use readlines('filename') to get the file contents.

d)

Open the file with open('filename', 'w') to read it.

19.

What are the different file modes available in Python?

a)

'read', 'write', 'append'

b)

'z', 'p', 'q'

c)

The different file modes available in Python are: 'r', 'w', 'a', 'b', 'x', 't'.

d)

'r+', 'w+', 'a+', 'c'

20.

What is the purpose of the 'len()' function in Python?

a)

To determine the length of a string or collection.

b)

To create a new list from an existing one.

c)

To convert a string to an integer.

d)

To check if a variable is defined.

21.

How do you handle exceptions in Python?

a)

Using 'catch' statements to manage exceptions.

b)

Using the 'try' and 'except' blocks to catch and handle exceptions.

c)

By using 'if' statements to check for errors.

d)

Exceptions cannot be handled in Python.

22.

What is the difference between a shallow copy and a deep copy in Python?

a)

A deep copy is only applicable to lists, while a shallow copy can be used for all data types.

b)

A shallow copy is faster than a deep copy.

c)

A shallow copy creates a new object but inserts references into it, while a deep copy creates a new object and recursively adds copies of nested objects.

d)

There is no difference; both terms refer to the same process.

23.

What is the purpose of the 'return' statement in a function?

a)

To create a loop within a function.

b)

To print output to the console from within a function.

c)

To exit a function and return control to the calling function.

d)

To define a function's parameters.

24.

What is the difference between a list and a set in Python?

a)

A list can only contain numeric values, while a set can contain any data type.

b)

A list is immutable, while a set is mutable.

c)

A list is ordered and allows duplicates, while a set is unordered and does not allow duplicates.

d)

A list is created using curly braces, while a set is created using square brackets.

25.

How can you concatenate two strings in Python?

a)

Using the 'append()' function to add strings together.

b)

Using the 'concat()' method to merge strings.

c)

Using the '+' operator to join two strings.

d)

Using the 'join()' method to concatenate strings.

26.
Which of the following is a valid variable name in Python?
a)
2var
b)
_var
c)
var-name
d)
none-of-the-above
27.
What will be the output of: print(type(3.14))?
a)
<class 'int'>
b)
<class 'float'>
c)
<class 'double'>
d)
<class 'str'>
28.
What is the correct syntax to take input from a user in Python?
a)
get(input)
b)
cin>>
c)
input()
d)
scan()
29.
Which of the following is NOT a Python keyword?
a)
continue
b)
function
c)
pass
d)
raise
30.
What is the output of print("5" + "3")?
a)
8
b)
53
c)
Error
d)
None
31.
What is the output of: print(4 > 2 and 3 < 1)?
a)
True
b)
False
c)
Error
d)
None
32.
Which keyword is used for loop termination?
a)
continue
b)
stop
c)
break
d)
exit
33.
The range(5) function generates:
a)
[1, 2, 3, 4, 5]
b)
[0, 1, 2, 3, 4]
c)
[0, 1, 2, 3, 4, 5]
d)
[1, 2, 3, 4]
34.
A loop inside another loop is called:
a)
recursive loop
b)
inner loop
c)
nested loop
d)
None
35.
What is the default step value in Python’s range()?
a)
0
b)
1
c)
2
d)
None
36.
A function that calls itself is called:
a)
nested function
b)
main function
c)
recursive function
d)
repeated function
37.
What is the keyword used to define a function?
a)
function
b)
def
c)
fun
d)
define
38.
What is returned if there is no return statement in a function?
a)
0
b)
False
c)
None
d)
Error
39.
The scope of a variable declared inside a function is:
a)
global
b)
universal
c)
local
d)
constant
40.
How do you call a function named 'myFunc'?
a)
call myFunc()
b)
myFunc[]
c)
myFunc()
d)
func(myFunc)
41.
What is the result of 'Python'[0]?
a)
P
b)
y
c)
n
d)
Error
42.
Which operator is used for list concatenation?
a)
*
b)
,
c)
+
d)
&
43.
Which of these is a valid list in Python?
a)
{1, 2, 3}
b)
(1, 2, 3)
c)
[1, 2, 3]
d)
<1, 2, 3>
44.
The method to add an item to the list is:
a)
add()
b)
insert()
c)
append()
d)
extend()
45.
Which method returns the number of items in a list?
a)
size()
b)
count()
c)
length()
d)
len()
46.
Which data structure does not allow duplicate values?
a)
List
b)
Tuple
c)
Set
d)
Dictionary
47.
What is the correct syntax to access a dictionary value?
a)
dict.get(key)
b)
dict[key]
c)
Both A and B
d)
dict.value(key)
48.
How to add a new item to a dictionary?
a)
dict.add()
b)
dict.insert()
c)
dict[key] = value
d)
dict.update()
49.
What will `set([1,2,2,3])` return?
a)
[1,2,3]
b)
{1,2,2,3}
c)
{1,2,3}
d)
set([1,2,3])
50.
What is the output of: len((1,2,3))?
a)
3
b)
2
c)
1
d)
Error
51.
Which mode is used to read from a file?
a)
w
b)
r
c)
a
d)
x
52.
Which block is used to handle exceptions in Python?
a)
catch
b)
try-except
c)
error
d)
exception
53.
Which function is used to write to a file?
a)
file.write()
b)
write.file()
c)
fprint()
d)
print.file()
54.
What does `with open()` do?
a)
Closes file manually
b)
Automatically closes file
c)
Writes content
d)
Reads file
55.
Which exception is raised when dividing by zero?
a)
ZeroDivisionError
b)
ValueError
c)
ArithmeticError
d)
TypeError
56.
Which keyword is used to create a class?
a)
def
b)
object
c)
class
d)
struct
57.
What is `__init__` in Python?
a)
Destructor
b)
Initializer
c)
Constructor
d)
Main method
58.
How to call parent class constructor?
a)
base()
b)
init()
c)
super()
d)
parent()
59.
Which keyword is used for inheritance?
a)
inherits
b)
extends
c)
base
d)
class
60.
Which keyword refers to the current object?
a)
this
b)
self
c)
object
d)
cls