Podcast
Questions and Answers
What is the output of $23+(5+6)(1+1)?$
What is the output of $23+(5+6)(1+1)?$
What will be the data type of 'var' after the following code snippet?
What will be the data type of 'var' after the following code snippet?
What will be the output of the following code snippet?
a = [1, 2, 3]
a = tuple(a)
a = 2
print(a)
What will be the output of the following code snippet?
a = [1, 2, 3]
a = tuple(a)
a = 2
print(a)
What is the output of $5/2$ and $5//2$?
What is the output of $5/2$ and $5//2$?
Signup and view all the answers
What will be the output of the following code snippet?
a = [1, 2, 3, 4, 5]
sum = 0
for ele in a:
sum += ele
print(sum)
What will be the output of the following code snippet?
a = [1, 2, 3, 4, 5]
sum = 0
for ele in a:
sum += ele
print(sum)
Signup and view all the answers
What will be the output of the following code snippet?
a=3
b=1
print(a, b)
a, b = b, a
print(a, b)
What will be the output of the following code snippet?
a=3
b=1
print(a, b)
a, b = b, a
print(a, b)
Signup and view all the answers
Which of the following is an invalid variable name in Python?
Which of the following is an invalid variable name in Python?
Signup and view all the answers
What is the result of $22 ext{ % }3$ in Python?
What is the result of $22 ext{ % }3$ in Python?
Signup and view all the answers
Which of the following CANNOT be a valid variable name in Python?
Which of the following CANNOT be a valid variable name in Python?
Signup and view all the answers
What is the correct operator for power($x^y$) in Python?
What is the correct operator for power($x^y$) in Python?
Signup and view all the answers
Which of the following statements is invalid in Python?
Which of the following statements is invalid in Python?
Signup and view all the answers
Which operator has the highest precedence in a Python expression?
Which operator has the highest precedence in a Python expression?
Signup and view all the answers
What data type is the object L = [1, 23, 'hello', 1]?
What data type is the object L = [1, 23, 'hello', 1]?
Signup and view all the answers
What is the output of the following Python code?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
What is the output of the following Python code? i=1 while True: if i%3 == 0: break print(i) i+=1
Signup and view all the answers
Which of the following Python code snippets results in a SyntaxError?
Which of the following Python code snippets results in a SyntaxError?
Signup and view all the answers
What will be the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
What will be the average value of the following Python code snippet? >>>grade1 = 80 >>>grade2 = 90 >>>average = (grade1 + grade2) / 2
Signup and view all the answers
What will be the output of the following Python code?
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
What will be the output of the following Python code? i=1 while True: if i%2 == 0: break print(i) i += 2
Signup and view all the answers
What will be the output of the following Python code?
i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
What will be the output of the following Python code? i=1 while False: if i%2 == 0: break print(i) i += 2
Signup and view all the answers
What will be the output of the following Python code? print('xyyzxyzxzxyy'.count('xy'))
What will be the output of the following Python code? print('xyyzxyzxzxyy'.count('xy'))
Signup and view all the answers
What will be the output of the following Python code? print('abcdef'.index('f'))
What will be the output of the following Python code? print('abcdef'.index('f'))
Signup and view all the answers
What will be the output of the following Python code? print('123abc'.isdigit())
What will be the output of the following Python code? print('123abc'.isdigit())
Signup and view all the answers
What will be the output of the following Python code? print('Hello'.replace('l', 'x'))
What will be the output of the following Python code? print('Hello'.replace('l', 'x'))
Signup and view all the answers
What will be the output of the following Python code? print('HeLLoWoRLd'.swapcase())
What will be the output of the following Python code? print('HeLLoWoRLd'.swapcase())
Signup and view all the answers
What will be the output of the following Python code? print('Python is fun'.split())
What will be the output of the following Python code? print('Python is fun'.split())
Signup and view all the answers
What is the output of len(list1) if list1 is ['apple', 'banana', 'cherry']?
What is the output of len(list1) if list1 is ['apple', 'banana', 'cherry']?
Signup and view all the answers
In list1 = [2, 4, 6, 8, 10], what does list1[2:4] return?
In list1 = [2, 4, 6, 8, 10], what does list1[2:4] return?
Signup and view all the answers
If list1 = [1, 2, 3] and list2 = [4, 5], what is the result of list1 + list2?
If list1 = [1, 2, 3] and list2 = [4, 5], what is the result of list1 + list2?
Signup and view all the answers
How can an element be removed by value from a list in Python?
How can an element be removed by value from a list in Python?
Signup and view all the answers
What is the correct way to copy the contents of list1 into a new list called list2?
What is the correct way to copy the contents of list1 into a new list called list2?
Signup and view all the answers
If list1 = [10, 20, 30] and list2 = list1, what happens if we modify list2[0] to 5?
If list1 = [10, 20, 30] and list2 = list1, what happens if we modify list2[0] to 5?
Signup and view all the answers
Study Notes
Python Basics
- In Python,
2**3 + (5 + 6)**(1 + 1)
evaluates to 129 -
print(type(var))
will outputstr
orint
depending on the type ofvar
-
a = [1, 2, 3]; a = tuple(a)
converts a list to a tuple -
print(type(5 / 2))
outputsfloat
andprint(type(5 // 2))
outputsint
-
a = [1, 2, 3, 4, 5]; sum = 0; for ele in a: sum += ele; print(sum)
outputs 15 -
a, b = b, a
swaps the values ofa
andb
Loops and Control Structures
-
while True:
creates an infinite loop -
break
statement exits a loop -
if i%3 == 0: break
exits a loop wheni
is a multiple of 3 -
if i%2 == 0: break
exits a loop wheni
is even
Data Types and Operations
-
L = [1, 23, 'hello', 1]
is a list -
dict
is used to store values in key-value pairs -
average = (grade1 + grade2) / 2
calculates the average of two numbers -
str.endswith("xyy")
checks if a string ends with "xyy" -
str.find("cd")
finds the index of the first occurrence of "cd" in a string -
str.format
is used to format strings
Functions and Operators
-
%
is the modulus operator -
**
is the exponentiation operator -
int(x)
converts a value to an integer -
str()
converts a value to a string -
print("xyyzxyzxzxyy".endswith("xyy"))
checks if a string ends with "xyy" -
print("abcdef".find("cd"))
finds the index of the first occurrence of "cd" in a string
Lists and Tuples
-
list[index]
accesses an element in a list -
list[index:]
slices a list fromindex
to the end -
list1 * 2
concatenates a list with itself -
list1.append(5)
adds an element to the end of a list -
list1.insert(2, 5)
inserts an element at a specific position in a list
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of Python with these multiple-choice questions covering topics such as arithmetic operations, data types, and data structures. See if you can predict the output of various code snippets and identify the data types of variables.