stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
CS1301 (Plus Session 1) Flashcards | StudBud
Explore
/
CS1301 (Plus Session 1)
CS1301 (Plus Session 1)
17 terms
·
StudBud Administration
·
10 plays
Imported from external platform
Flashcards
17 cards
F
Practice quiz
P
Host live
L
Questions
17
Answers
1
What is a variable in Python?
A function that performs mathematical operations
A reserved keyword in Python
A value that cannot change
A placeholder for storing data
2
What is Python primarily known for?
Compatibility issues
Readability and Versatility
Its use in programming games only
Being difficult to read
3
How can you iterate through a string in reverse order using a
for
loop in Python?
Use slicing [::-1], assign it to a variable, and iterate through that
Use a negative step like for i in range(len(my_string) - 1, -1, -1):
Python does not support iterating through strings in reverse.
Use a positive step like for i in range(len(my_string)):
4
What are functions in Python?
A way to write comments in your code
Pre-made programs that you can use as is
Complex data types
Reusable blocks of code that perform specific tasks
5
Given a string
data
=
"apple,banana,cherry,date"
, how can you slice the string to obtain the substring "banana"?
data.split(' ')[1]
data.split(',')[0]
data.split(',')[1]
6
What type of loop is best suited for iterating over the elements of a list and applying a condition to each element?
while loop
for loop
7
What does the following code print?
Empty string
nohtyP
Error
Python
8
Given the list
my_list = [10, 20, 30, 40, 50]
, what is the index of the value
30
?
3
2
0
1
9
What is the result of the expression: 15 / 2?
8
7.5 with a remainder
7
7.5
10
What will be printed by the following code?
HelloWorld
"Hello"
Hello
World
11
You have a string
my_string = "PythonIsFun"
. What code will extract the substring "Is" from
my_string
?
my_string[7:9]
my_string[4:6]
my_string[2:4]
my_string[6:8]
12
What keyword is used to exit a function and return a value in Python?
exit
print
return
break
13
Which built-in function can be used to determine the length of a string?
len()
length()
14
Which of the following is a valid data type in Python?
str (string)
boolean (bools)
int (integer)
float (floating-point number)
15
How many times will the following loop run?
1
5
6
4
16
What if we tweaked it :)
"World"
Hello
HelloWorld
World
17
Which type of loop in Python executes a block of code repeatedly as long as a specified condition is true?
For loop
While Loop