Podcast
Questions and Answers
What is the output of $23+(5+6)(1+1)?$
What is the output of $23+(5+6)(1+1)?$
- 17 (correct)
- 121
- 8
- 129
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?
- str and str
- int and int
- str and int (correct)
- int and str
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)
- (2, 2, 3)
- Error. (correct)
- [2, 2, 3]
- (1, 2, 3)
What is the output of $5/2$ and $5//2$?
What is the output of $5/2$ and $5//2$?
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)
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)
Which of the following is an invalid variable name in Python?
Which of the following is an invalid variable name in Python?
What is the result of $22 ext{ % }3$ in Python?
What is the result of $22 ext{ % }3$ in Python?
Which of the following CANNOT be a valid variable name in Python?
Which of the following CANNOT be a valid variable name in Python?
What is the correct operator for power($x^y$) in Python?
What is the correct operator for power($x^y$) in Python?
Which of the following statements is invalid in Python?
Which of the following statements is invalid in Python?
Which operator has the highest precedence in a Python expression?
Which operator has the highest precedence in a Python expression?
What data type is the object L = [1, 23, 'hello', 1]?
What data type is the object L = [1, 23, 'hello', 1]?
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
Which of the following Python code snippets results in a SyntaxError?
Which of the following Python code snippets results in a SyntaxError?
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
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
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
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'))
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'))
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())
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'))
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())
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())
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']?
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?
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?
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?
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?
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?
Flashcards
Output of 23 + (5+6)(1+1)
Output of 23 + (5+6)(1+1)
The result of the calculation 2 multiplied by 3 plus the product of (5 plus 6) and (1 plus 1).
Data type of 'var' after code snippet
Data type of 'var' after code snippet
The variable "var" becomes a string and an integer.
Python list to tuple conversion
Python list to tuple conversion
Converts a list to a tuple in Python using the tuple()
function.
Output of 5/2
Output of 5/2
Signup and view all the flashcards
Output of 5//2
Output of 5//2
Signup and view all the flashcards
Summing elements in a list
Summing elements in a list
Signup and view all the flashcards
Output of a=3,b=1, swapping
Output of a=3,b=1, swapping
Signup and view all the flashcards
Invalid variable name
Invalid variable name
Signup and view all the flashcards
Modulo operation (22 % 3)
Modulo operation (22 % 3)
Signup and view all the flashcards
Invalid Python variable
Invalid Python variable
Signup and view all the flashcards
Power operator in Python
Power operator in Python
Signup and view all the flashcards
Invalid Python statement
Invalid Python statement
Signup and view all the flashcards
Highest precedence operator
Highest precedence operator
Signup and view all the flashcards
Data type of L = [1,23,'hello',1]
Data type of L = [1,23,'hello',1]
Signup and view all the flashcards
Output of while loop i % 3 ==0
Output of while loop i % 3 ==0
Signup and view all the flashcards
Syntax error (example)
Syntax error (example)
Signup and view all the flashcards
Average calculation (grade1+grade2)/2
Average calculation (grade1+grade2)/2
Signup and view all the flashcards
Output of while loop i % 2 ==0
Output of while loop i % 2 ==0
Signup and view all the flashcards
Output while loop with false condition
Output while loop with false condition
Signup and view all the flashcards
Count occurrences
Count occurrences
Signup and view all the flashcards
Index of substring
Index of substring
Signup and view all the flashcards
Check digits only
Check digits only
Signup and view all the flashcards
String replacement
String replacement
Signup and view all the flashcards
String case conversion
String case conversion
Signup and view all the flashcards
String splitting
String splitting
Signup and view all the flashcards
Length of a list
Length of a list
Signup and view all the flashcards
List slicing
List slicing
Signup and view all the flashcards
List concatenation
List concatenation
Signup and view all the flashcards
Removing element from a list (by value)
Removing element from a list (by value)
Signup and view all the flashcards
Copying a list
Copying a list
Signup and view all the flashcards
Modifications affect original list
Modifications affect original list
Signup and view all the flashcards
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 tupleprint(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 15a, b = b, a
swaps the values ofa
andb
Loops and Control Structures
while True:
creates an infinite loopbreak
statement exits a loopif i%3 == 0: break
exits a loop wheni
is a multiple of 3if i%2 == 0: break
exits a loop wheni
is even
Data Types and Operations
L = [1, 23, 'hello', 1]
is a listdict
is used to store values in key-value pairsaverage = (grade1 + grade2) / 2
calculates the average of two numbersstr.endswith("xyy")
checks if a string ends with "xyy"str.find("cd")
finds the index of the first occurrence of "cd" in a stringstr.format
is used to format strings
Functions and Operators
%
is the modulus operator**
is the exponentiation operatorint(x)
converts a value to an integerstr()
converts a value to a stringprint("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 listlist[index:]
slices a list fromindex
to the endlist1 * 2
concatenates a list with itselflist1.append(5)
adds an element to the end of a listlist1.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.