wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Basics

Total questions: 25

Worksheet time: 8mins

Name
Class
Date
1.

What is a correct syntax to output "Hello World" in Python?

a)

printf("Hello World");

b)

print("Hello World")

c)

echo "Hello World"

d)

print("Hello World"):

2.

What is the purpose of using Python?

a)

Python is used for various purposes such as web development, data analysis, artificial intelligence, scientific computing, automation, and more.

b)

Python is primarily used for video editing

c)

Python is only used for gaming development

d)

Python is exclusively used for accounting purposes

3.

How do you insert COMMENTS in Python code?

a)

//This is a comment

b)

#This is a comment

c)

/*This is a comment*/

d)

"This is a comment"

4.

What is the output of 'print(5 + 3)'?

a)

7

b)

10

c)

8

d)

2

5.

Which one is NOT a legal variable name?

a)

_myvar

b)

my_var

c)

Myvar

d)

my-var

6.

What is the keyword used for defining a function in Python?

a)

function

b)

define

c)

func

d)

def

7.

What is the result of '5 == 5'?

a)

error

b)

true

c)

10

d)

false

8.

How do you check the length of a list in Python?

a)

length(your_list_name)

b)

size(your_list_name)

c)

count(your_list_name)

d)

len(your_list_name)

9.

What is the output of 'print('Hello' + 'World')'?

a)

Hello World

b)

HelloWorldd

c)

WorldHello

d)

HelloWorld

10.

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

a)

To define a function

b)

Conditional execution

c)

To print output

d)

To loop through a list

11.

How do you create a variable with the numeric value 5?

a)

Both the other answers are correct

b)

Conditional executionx = int(5)

c)

x = 5

12.

What is the correct file extension for Python files?

a)

.py

b)

.pyt

c)

.pt

d)

.pyth

13.

How do you create a variable with the floating number 2.8?

a)

x = 2.8

b)

Both the other answers are correct

c)

x = float(2.8)

14.

What is the correct syntax to output the type of a variable or object in Python?

a)

print(typeof(x))

b)

print(type(x))

c)

print(typeof x)

d)

print(typeOf(x))

15.

What is the correct way to create a function in Python?

a)

function myfunction():

b)

def myFunction():

c)

create myFunction():

d)

def myFunction()

16.

In Python, 'Hello', is the same as "Hello"

a)

False

b)

True

17.

What is a correct syntax to return the first character in a string?

a)

x = "Hello"[0]

b)

x = sub("Hello", 0, 1)

c)

x = "Hello".sub(0, 1)

d)

x = "Hello[0]"

18.

How do you remove an item from a list in Python?

a)

list.remove(item)

b)

list.delete(item)

c)

list.pop(item)

d)

list.discard(item)

19.

Which method can be used to remove any whitespace from both the beginning and the end of a string?

a)

trim()

b)

strip()

c)

len()

d)

ptrim()

20.

Which method can be used to return a string in upper case letters?

a)

toUpperCase()

b)

upperCase()

c)

uppercase()

d)

upper()

21.

Which method can be used to replace parts of a string?

a)

repl()

b)

replaceString()

c)

switch()

d)

replace()

22.

Which operator is used to multiply numbers?

a)

%

b)

*

c)

x

d)

**

23.

Which operator can be used to compare two values?

a)

=

b)

==

c)

<>

d)

All of these.

24.

Which of these collections defines a LIST?

a)

("apple", "banana", "cherry")

b)

{"name": "apple", "color": "green"}

c)

["apple", "banana", "cherry"]

d)

{"apple", "banana", "cherry"}

25.

Which of these collections defines a TUPLE?

a)

{"name": "apple", "color": "green"}

b)

["apple", "banana", "cherry"]

c)

{"apple", "banana", "cherry"}

d)

("apple", "banana", "cherry")