wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Fundamental Python

Total questions: 76

Worksheet time: 38mins

Name
Class
Date
1.

Is Python case sensitive when dealing with identifiers?

a)

Yes

b)

No

2.

Mathematical operations can be performed on a string.

a)

True

b)

False

3.

Which of the following has the highest precedence in the expression?

a)

Addition

b)

Exponential

c)

Multiplication

d)

Parentheses

4.

Which of the following data types is not supported in Python?

a)

String

b)

Numbers

c)

Slice

d)

List

5.

Which one of the following is NOT a Python's predefined data type?

a)

List

b)

Dictionary

c)

Tuple

d)

Class

6.

Which of the following has more precedance?

a)

/

b)

+

c)

()

d)

-

7.

Choose the INVALID identifiers from the following

a)

NUmbEr1

b)

1NUMBer

c)

A_B

d)

A&B

8.

Examples of String Literals

a)

"ABC1273"

b)

nfjdlsj@@$

c)

12638

d)

'7e920938'

9.

Escape sequence is represented by a ____ followed by one or more characters

a)

Front slash

b)

Double Quote

c)

Single Quote

d)

Back Slash

10.

Size of the string "Ant Man"

(a)  

11.

str="Red\

block\

a"

Size of str is 11. True/False ?

a)

True

b)

False

12.

Select the valid Octal integer literals

a)

0836

b)

7976

c)

07362

d)

0x1726

13.

An escape sequence represents how many characters ?

"\t"

a)

3

b)

2

c)

1

d)

4

14.

Which of the following is a Boolean literal ?

a)

True

b)

false

c)

False

d)

true

15.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
16.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
17.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

18.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)

It displays an output

d)
It loops the code.
19.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
20.

What is the output from the following code?

print ("hello world")

a)
Hello World
b)
hello world
c)
print hello world
21.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

22.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

23.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

The list will be slice and show Harry and Jesse only. Which piece of code below would do this?

a)

print(nameList[1:3])

b)

print(nameList[0:1])

c)

print(nameList[1:2])

d)

print(nameList["Harry":"Jesse"])

24.

To insert an the string "Pedro" in the first position of a the nameList we use

a)

nameList.append("Pedro, 1")

b)

nameList.insert("Pedro",0)

c)

nameList.insert(1, "Pedro")

d)

nameList.insert(0, "Pedro")

25.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

26.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

del nameList[3]

print(nameList)

What would be the output

a)

['John', 'Harry', 'Jesse', 'Marry', 'Larry']

b)

['John', 'Harry', 'Jesse', 'John', 'Larry']

c)

['John', 'Harry', 'John', 'Marry', 'Larry']

d)

Error

27.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

print(nameList.count("John"))

What would be the output

a)

1

b)

2

c)

3

d)

Error

28.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

nameList[6] ="Susie"

print(nameList)

What would be the output

a)

['John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry', 'Susie']

b)

['Susie', 'John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry']

c)

['Susie']

d)

Error

29.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
30.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

31.

Output of this code?

a)

[2,4,6,8,10]

b)

['2','4','6','8','10']

c)

[0,2,4,6,8]

d)

[10,8,6,4,2]

32.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

33.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

34.

Tuples in Python are mutable

a)

False

b)

True

35.

CAN A VALUE IN A TUPLE BE EDITED?

a)

YES, IT CAN BE DONE JUST AS WE DO WITH LISTS

b)

NO, TUPLE IS AN IMMUTABLE DATA TYPE

36.

Dictionary keys must be immutable

a)

True

b)

False

37.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

38.

_______________this method deletes the item from the dictionary

a)

pop( )

b)

del( )

c)

clear( )

39.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
40.

A collection of objects which ordered, immutable, and allows duplicate values.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

41.

A collection that is unordered, changeable, and does not allow duplicates.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

42.

A collection which is unordered and unindexed.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

43.

It is simply a file containing python code, it may contain functions, classes, etc.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

44.

Which symbol surrounds a tuple?

a)
{
b)
(
c)
[
d)
:
45.

Which symbol surrounds a Sets?

a)
{
b)
(
c)
[
d)
:
46.

Which operator is used to concatenate?

a)

+

b)

-

c)

/

d)

*

47.

It returns an item from the tuple with a max value.

a)

max(t)

b)

min(t)

48.

It returns an item from the tuple with a min value.

a)

max(t)

b)

min(t)

49.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

50.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

51.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

52.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

53.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

54.

What is the output of the program above ?

a)

True

b)

False

55.
What type of flowchart is shown here?
a)
selection
b)
iteration / loop
c)
sequence
56.
What is the Output if the user enters:
Yes
a)
Leave umbrella at home
b)
Take an umbrella
57.

In a Python program , a control structure:

a)

directs the order of execution of the statements in the program

b)

dictates what happens before te program starts and after it terminates

c)

defines program-specific data structures

d)

manages the input and output of control characters

58.

What is the output of the above program ?

a)

Am I here?

b)

Or here ?

c)

Am I here ? Or here ?

d)

Or here ? Or over here ?

59.

If the user inputs : 2<Enter> , what does the following code snippet print ?

a)

Yes

b)

No

c)

May be

d)

Nothing printed

e)

Error

60.

Function range(3) is equivalent to "

a)

range(1,3)

b)

range(0,3)

c)

range(0,3,1)

d)

range(1,3,0)

61.

Consider the following loop given below :


for i in range(5):

print(i)


How many times will this loop run ?

a)

5

b)

0

c)

infinite

d)

Error

62.
This operator means that one value is not equal to another value
a)
==
b)
<=
c)
>=
d)
!=
63.

What is the output?

a)

condition

b)

True

c)

Program has a syntax error.

d)

3 > 2

64.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

65.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

66.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

67.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

68.

An If statement can be executed multiple times

a)

FALSE

b)

TRUE

69.

The ‘else’ statement is optional in Python

a)

TRUE

b)

FALSE

70.

It is possible to execute both the statements under if and else at the same time.

a)

TRUE

b)

FALSE

71.

There can be an else statement without an if statement

a)

FALSE

b)

TRUE

72.

The relational operators cannot be used within a if condition

a)

FALSE

b)

TRUE

73.

The program generates an error message if the "else" statement is not defined

a)

FALSE

b)

TRUE

74.

What is the output?

a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
75.

What is the output if the user types "Python"?

a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
76.
I want to allow the program to repeatedly ask the user to enter their guess if it does not equal the answer...Which option do I use?
a)
while guess == answer:
    guess=input()
b)
while answer != guess:
guess=input()
c)
while answer =! guess:
guess=input()
d)
while guess != answer:
guess=input()