Computer Science
From the following, find out which assignment statement will produce an error. State reason(s) too.
(a) x = 55
(b) y = 037
(c) z = 0o98
(d) 56thnumber = 3300
(e) length = 450.17
(f) !Taylor = 'Instant'
(g) this variable = 87.E02
(h) float = .17E - 03
(i) FLOAT = 0.17E - 03
Python Funda
90 Likes
Answer
- y = 037 (option b) will give an error as decimal integer literal cannot start with a 0.
- z = 0o98 (option c) will give an error as 0o98 is an octal integer literal due to the 0o prefix and 8 & 9 are invalid digits in an octal number.
- 56thnumber = 3300 (option d) will give an error as 56thnumber is an invalid identifier because it starts with a digit.
- !Taylor = 'Instant' (option f) will give an error as !Taylor is an invalid identifier because it contains the special character !.
- this variable = 87.E02 (option g) will give an error due to the space present between this and variable. Identifiers cannot contain any space.
- float = .17E - 03 (option h) will give an error due to the spaces present in exponent part (E - 03). A very important point to note here is that float is NOT a KEYWORD in Python. The statement float = .17E-03 will execute successfully without any errors in Python.
- FLOAT = 0.17E - 03 (option i) will give an error due to the spaces present in exponent part (E - 03).
Answered By
35 Likes
Related Questions
Following variable definition is creating problem X = 0281, find reasons.
"Comments are useful and easy way to enhance readability and understandability of a program." Elaborate with examples.
How will Python evaluate the following expression ?
20 + 30 * 40
How will Python evaluate the following expression ?
20 - 30 + 40