Test Index

CBSE Class 12 Computer Science 2025 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 23 of 37
Marks: +1, -0
Write one example of each of the following in Python :
(i) Syntax Error
(ii) Implicit Type Conversion
Solution:  
(i) Syntax Error
A syntax error occurs when a statement breaks the grammar rules of Python, so the program does not run at all.
print(2 ; 5)        # SyntaxError: invalid syntax
Another example: a missing colon after if.
if x > 5             # SyntaxError: expected ':'
print(x)
(ii) Implicit Type Conversion
Python itself converts one data type to another (a smaller type to a wider type) during an operation, without the programmer asking for it.
x = 10           # int
y = 20.5 # float
z = x + y # x is converted to float automatically
print(z) # 30.5
print(type(z)) # <class 'float'>
The int value 10 is converted to the float 10.0 before the addition, so the result is a float.
© examsnet.com
Advertisements
Go to Question: