Python Type Casting Quiz

Python
0 Passed
0% acceptance

A 50-question quiz covering Python type casting: numeric conversions, string casting, boolean rules, safe casting, error cases, and real-world usage patterns.

50 Questions
~100 minutes
1

Question 1

What is type casting in Python?

A
Changing a value from one data type to another
B
Removing all whitespace
C
Executing a script twice
D
Converting code into machine language
2

Question 2

Which type of casting does Python primarily rely on?

A
Explicit casting
B
Automatic deep casting
C
Hardware casting
D
HTML-style casting
3

Question 3

Which function converts a value into a string?

A
str()
B
stringOf()
C
convertString()
D
toText()
4

Question 4

Which function converts compatible strings into integers?

A
int()
B
number()
C
digit()
D
integerOf()
5

Question 5

What is the typical result of converting an incompatible string using int()?

A
A ValueError
B
0
C
None
D
An empty string
6

Question 6

Which function converts a value into a floating-point number?

A
float()
B
real()
C
decimal()
D
fraction()
7

Question 7

Which type does bool() return?

A
True or False
B
1 or 0 only
C
String values only
D
None
8

Question 8

What does list() do when passed a string?

A
Creates a list of characters
B
Creates a list containing the entire string as one item
C
Always returns an empty list
D
Raises an error
9

Question 9

What happens when casting a float like 7.9 to int()?

A
It truncates to 7
B
It rounds to 8
C
It raises ValueError
D
It always returns 0
10

Question 10

Which casting function removes decimal places but does not round?

A
int()
B
round()
C
float()
D
bool()
11

Question 11

What is the output of this code?

python
print(int("42"))
A
42
B
'42'
C
Error
D
None
12

Question 12

What does this print?

python
print(float("3.14"))
A
3.14
B
'3.14'
C
Error
D
3
13

Question 13

What is the result?

python
print(bool(""))
A
False
B
True
C
None
D
''
14

Question 14

What happens here?

python
print(int("3.5"))
A
ValueError
B
3
C
4
D
3.5
15

Question 15

What does this print?

python
print(str(100))
A
'100'
B
100
C
1
D
Error
16

Question 16

What does this code output?

python
x = "abc"
      print(list(x))
A
['a','b','c']
B
['abc']
C
('a','b','c')
D
Error
17

Question 17

What is printed?

python
print(bool([]))
A
False
B
True
C
None
D
[]
18

Question 18

What is the output?

python
print(float(7))
A
7.0
B
7
C
'7.0'
D
Error
19

Question 19

What does this display?

python
print(int(True))
A
1
B
0
C
True
D
Error
20

Question 20

What happens here?

python
print(int(False))
A
0
B
1
C
False
D
Error
21

Question 21

What does this produce?

python
print(str([1,2]))
A
'[1, 2]'
B
['1','2']
C
1 2
D
Error
22

Question 22

What is printed?

python
print(tuple("hi"))
A
('h','i')
B
('hi')
C
['h','i']
D
Error
23

Question 23

What does this print?

python
print(set("aaab"))
A
{'a','b'}
B
{'aaab'}
C
['a','b']
D
Error
24

Question 24

What is printed?

python
print(float("5"))
A
5.0
B
5
C
'5.0'
D
Error
25

Question 25

What is the output?

python
print(bool("False"))
A
True
B
False
C
Error
D
None
26

Question 26

What does this code output?

python
print(str(3.5))
A
'3.5'
B
3.5
C
'3'
D
Error
27

Question 27

What results from this?

python
print(int(3.99))
A
3
B
4
C
Error
D
'3'
28

Question 28

What does this produce?

python
print(str(True))
A
'True'
B
'1'
C
True
D
Error
29

Question 29

What is printed?

python
print(float(False))
A
0.0
B
1.0
C
False
D
Error
30

Question 30

What occurs here?

python
print(int("abc"))
A
ValueError
B
0
C
None
D
'abc'
31

Question 31

What is the result?

python
print(list((1,2,3)))
A
[1,2,3]
B
(1,2,3)
C
['1','2','3']
D
Error
32

Question 32

What is shown?

python
print(tuple([4,5]))
A
(4,5)
B
[4,5]
C
{4,5}
D
Error
33

Question 33

Output?

python
print(set([1,1,2,3]))
A
{1,2,3}
B
{1,1,2,3}
C
[1,2,3]
D
(1,2,3)
34

Question 34

What does this code display?

python
print(bool("0"))
A
True
B
False
C
0
D
Error
35

Question 35

What happens here?

python
print(int(5.01))
A
5
B
6
C
Error
D
'5'
36

Question 36

What does bool(0) return?

A
False
B
True
C
None
D
Error
37

Question 37

Which conversion is guaranteed to succeed?

A
str(any_value)
B
int('hello')
C
float('abc')
D
list(5)
38

Question 38

What does the term 'explicit casting' refer to?

A
Using functions like int() or float()
B
Automatically converting numbers
C
Casting without programmer involvement
D
Converting files between formats
39

Question 39

Which value becomes True when cast with bool()?

A
Any non-empty list
B
0
C
''
D
None
40

Question 40

Which function turns an iterable into a tuple?

A
tuple()
B
pack()
C
toTuple()
D
wrap()
41

Question 41

Which conversion produces a loss of precision?

A
Casting float to int
B
Casting int to float
C
Casting string to list
D
Casting list to tuple
42

Question 42

Which value is safe to convert using float()?

A
'7.2'
B
'abc'
C
''
D
'seven'
43

Question 43

What does casting a list into a set do?

A
Removes duplicates
B
Maintains ordering
C
Creates a new list
D
Prevents iteration
44

Question 44

Which casting function accepts any Python object?

A
str()
B
int()
C
float()
D
tuple()
45

Question 45

Casting which object to bool() will return False?

A
None
B
[1]
C
'text'
D
(3,)
46

Question 46

Which conversion is valid?

A
list((1,2))
B
int({'a':1})
C
float([1,2])
D
tuple(5)
47

Question 47

Which type can always be converted to a string without error?

A
Any Python type
B
Only numeric types
C
Only strings
D
Only booleans
48

Question 48

Which describes implicit casting in Python?

A
Automatically promoting ints to floats in arithmetic
B
Converting strings to ints automatically
C
Turning objects into lists automatically
D
Replacing variable values without user action
49

Question 49

Which casting behavior is considered unsafe?

A
Using int() on a user-provided string
B
Using str() on any object
C
Casting lists to tuples
D
Casting ints to floats
50

Question 50

Which practice helps avoid casting errors?

A
Validating the data before casting
B
Casting values randomly
C
Avoiding type checking fully
D
Assuming user input is always numeric

QUIZZES IN Python