
Python Quiz

Quiz
•
Computers
•
University
•
Hard
SATISH V
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
Which of the following is a correct way to define a variable in Python?
variable 1 = 10
var = 10
10 = var
var @ 10
Answer explanation
In Python, the correct way to define a variable is by using the format 'var = value'. Therefore, 'var = 10' is the correct choice out of the options provided.
2.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will be the output of the following code snippet? python Copy code x = 5 y = 2 print(x / y)
2.5
2
2.0
2.2
Answer explanation
The output will be 2.5 because when dividing two integers in Python, the result is a float if there is a remainder.
3.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
Which of the following statements is true about Python lists?
Lists are immutable.
Lists can contain elements of different data types.
Lists are indexed starting from 1.
Lists are a fixed-size collection.
Answer explanation
Lists can contain elements of different data types.
4.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What does the range() function in Python do?
Generates a list of integers starting from 0 up to a specified number.
Generates a sequence of numbers.
Generates a range object.
All of the above.
Answer explanation
The range() function in Python generates a sequence of numbers, not a list of integers starting from 0 up to a specified number or a range object. Therefore, the correct choice is 'Generates a sequence of numbers.'
5.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
How do you check the number of elements in a list my_list in Python?
len(my_list)
my_list.size()
my_list.length()
count(my_list)
Answer explanation
To check the number of elements in a list in Python, you use the len(my_list) function. This returns the length of the list.
6.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the output of the following code snippet? python Copy code my_string = "Hello, World!" print(my_string[3:7])
lo,
lo, W
llo,
llo, W
Answer explanation
The output of the code snippet is 'lo,' because string slicing in Python starts from the index specified before the colon and goes up to, but does not include, the index specified after the colon.
7.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
Which of the following is a correct way to open a file named data.txt for reading in Python?
open('data.txt', 'r')
open('data.txt', 'read')
open('data.txt', 'w')
open('data.txt')
Answer explanation
The correct way to open a file named data.txt for reading in Python is open('data.txt', 'r'). The 'r' mode stands for read.
Create a free account and access millions of resources
Similar Resources on Wayground
16 questions
Python Workshop 1 review

Quiz
•
University
20 questions
Guess the CS Term!

Quiz
•
University
15 questions
ATP_AIML_D1_Reflections

Quiz
•
University - Professi...
20 questions
Data Science Quiz

Quiz
•
University
23 questions
C que que que

Quiz
•
University
18 questions
Data Structures Quiz 1

Quiz
•
12th Grade - University
20 questions
GirlsWhoML Workshop 0

Quiz
•
University
15 questions
Bootcamp Day 3 - Java Array

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Would you rather...

Quiz
•
KG - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
10 questions
The Constitution, the Articles, and Federalism Crash Course US History

Interactive video
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
16 questions
Water Modeling Activity

Lesson
•
11th Grade - University
10 questions
ACT English prep

Quiz
•
9th Grade - University