Playing as a guest? to earn XP and track your progress.
๐ข Data Handling Quiz
๐ข Data Handling
What is the data type of 25 in Python?
bool
int
float
str
Whole numbers without a decimal point are integers (int).
What is the output of:
print(type(3.0))3.0
<class 'float'>
<class 'str'>
<class 'int'>
A number with a decimal point is a float, even if the decimal part is 0.
2.5E3 represents which value?
2.53
2500.0
25000.0
0.0025
E3 means ร 10ยณ, so 2.5E3 = 2500.0.
Which of these is a complex number in Python?
3 + 4j
3 + 4i
(3, 4)
3.4
Python uses j for the imaginary part of a complex number.
What is the output of:
print(True + True)Error
2
True
TrueTrue
In arithmetic, True counts as 1 and False as 0.
Which data type has only two values, True and False?
NoneType
int
bool
str
bool (Boolean) values are True and False.
What is the output of:
print(type("25"))<class 'str'>
25
<class 'float'>
<class 'int'>
Anything inside quotes is a string.
Which brackets are used to make a list?
Square brackets [ ]
Angle brackets < >
Curly brackets { }
Round brackets ( )
A list is written as [10, 20, 30].
Which brackets are used to make a tuple?
Round brackets ( )
Quotes " "
Curly brackets { }
Square brackets [ ]
A tuple is written as (10, 20, 30).
A dictionary stores data as:
Only values
Index : value pairs that can't change
Rows and columns
key : value pairs
A dictionary is written as {"Riya": 92, "Aman": 78}.
String, list and tuple are all:
Numeric types
Boolean types
Sequence types
Mapping types
Sequences keep items in order and allow indexing from 0.
What is the output of:
print("PYTHON"[0])Error
Y
N
P
Indexing starts at 0, so index 0 is the first character.
What is the output of:
print(type(None))<class 'None'>
<class 'NoneType'>
None
<class 'str'>
None has its own type, NoneType.
Which of these is a MUTABLE type?
tuple
int
list
str
Lists (and dictionaries) can be changed in place; str, tuple and int cannot.
Which of these is an IMMUTABLE type?
tuple
list
dict
None of these
A tuple cannot be changed after it is created.
What happens when you run:
s = "cat"
s[0] = "b"IndexError
s becomes 'bat'
s becomes 'bcat'
TypeError
Strings are immutable; you cannot change a character inside one.
What is the output of:
L = [1, 2, 3]
L[0] = 9
print(L)Error
[9, 2, 3]
[9, 1, 2, 3]
[1, 2, 3]
Lists are mutable, so an item can be changed.
What is the output of:
print(7 / 2)1
4
3.5
3
/ always gives a float result.
What is the output of:
print(7 // 2)4
3.5
1
3
// is floor division; it gives the quotient without the decimal part.
What is the output of:
print(7 % 2)0
3
3.5
1
% gives the remainder: 7 = 2 ร 3 + 1.
What is the output of:
print(2 ** 3)6
9
8
5
** is the power operator: 2ยณ = 8.
What is the output of:
print(10 / 5)0.5
2
2.0
50
/ always returns a float, even when the answer is whole.
What is the output of:
print(-7 // 2)3
-3
-3.5
-4
Floor division rounds DOWN, so โ3.5 becomes โ4.
Which operator gives the remainder of a division?
**
%
/
//
% is the modulus (remainder) operator.
What is the output of:
print(10 > 5)10
False
True
Error
10 is greater than 5, so the comparison is True.
Which operator checks whether two values are EQUAL?
!=
=
=>
==
== compares; = assigns a value.
What is the output of:
print(5 != 5)False
True
5
Error
!= means 'not equal to'; 5 is equal to 5, so the answer is False.
What is the output of:
print("a" < "b")False
ab
True
Error
Strings are compared letter by letter in alphabetical (Unicode) order.
What is the output of:
print(5 > 3 and 2 > 4)False
True
None
Error
and is True only if BOTH sides are True; 2 > 4 is False.
What is the output of:
print(5 > 3 or 2 > 4)True
Error
None
False
or is True if EITHER side is True.
What is the output of:
print(not True)Error
None
False
True
not reverses the value.
What is the value of x after:
x = 10
x += 510
5
105
15
x += 5 means x = x + 5.
What is the value of x after:
x = 20
x //= 36
6.67
2
7
x //= 3 means x = x // 3 = 6.
What happens when you write x++ in Python?
x increases by 1
x doubles
SyntaxError โ Python has no ++ operator
x becomes 0
Python has no ++; write x += 1 instead.
What is the output of:
print("a" in "apple")Error
1
True
False
in checks whether a value is present in a sequence.
What is the output of:
print(4 not in [1, 2, 3])Error
None
True
False
4 is not in the list, so not in gives True.
What is the output of:
print(2 + 3 * 4)14
20
9
24
* has higher precedence than +, so 3 * 4 is done first.
What is the output of:
print((2 + 3) * 4)9
14
24
20
Brackets are evaluated first.
What is the output of:
print(2 ** 3 ** 2)512
36
12
64
** works right to left: 3 ** 2 = 9, then 2 ** 9 = 512.
What is the output of:
print(10 - 4 - 2)6
8
0
4
Operators of the same priority work left to right: (10 โ 4) โ 2.
Which operator has the HIGHEST precedence?
*
+
**
and
After brackets, ** has the highest priority.
Which logical operator is evaluated FIRST?
or
and
not
All are equal
The order is not, then and, then or.
What is the output of:
print(15 % 4 + 2 ** 2)7
5
9
11
2 ** 2 = 4 first, then 15 % 4 = 3, and 3 + 4 = 7.
What is the output of:
print(3 + 4.0)Error
7.0
7
34.0
int + float gives a float (implicit conversion).
Python automatically converting int to float in 3 + 4.0 is called:
Implicit type conversion
Type casting by the user
Syntax error
Explicit type conversion
Implicit conversion is done automatically by Python.
Converting a value yourself, like int("5"), is called:
Implicit conversion
Explicit conversion (type casting)
Indexing
Concatenation
Explicit conversion uses functions like int(), float() and str().
What is the output of:
print(int(7.9))8
7.9
Error
7
int() cuts off the decimal part; it does not round.
What is the output of:
print(float(5))5
5.00
5.0
Error
float() converts an integer to a float.
What is the output of:
print(str(10) + "0")10
100
10 0
Error
str(10) is '10', and joining it with '0' gives '100'.
What is the output of:
print(bool(0))0
False
True
None
0 is treated as False.
What is the output of:
print(bool(""))None
True
False
Error
An empty string is treated as False.
What is the output of:
print(bool("0"))0
Error
True
False
"0" is a non-empty string, so it is True.
What is the output of:
print("5" + 5)TypeError
10
5 5
55
A string and an integer cannot be added.
An error caused by breaking Python's grammar rules, so the program does not run at all, is a:
Syntax error
Logical error
Runtime error
Semantic warning
Syntax errors are found before the program runs.
An error that occurs while the program is running, like dividing by zero, is a:
Syntax error
Logical error
Runtime error
Compile error
Runtime errors stop the program in the middle.
What error does print(10 / 0) give?
TypeError
ValueError
SyntaxError
ZeroDivisionError
Dividing by zero is not possible.
A program to find the average uses avg = a + b / 2. It runs but gives a wrong answer. This is a:
Runtime error
Syntax error
NameError
Logical error
It runs without any message but the result is wrong; it should be (a + b) / 2.
Which error is the HARDEST to find, because Python shows no error message?
Syntax error
IndentationError
Logical error
Runtime error
A logical error gives a wrong result silently.
Finding and removing errors from a program is called:
Compiling
Debugging
Casting
Indenting
Debugging means locating and fixing errors (bugs).