Computer Science
Identify invalid variable names from the following, giving reason for each:
Group, if, total marks, S.I., volume, tot_strength, #tag, tag, 9a, for
Python Funda
1 Like
Answer
Group — This is a valid variable name.
if — This is an invalid variable name because
if
is a reserved keyword in Python and cannot be used as a variable name.total marks — This is an invalid variable name because it contains a space, which is not allowed in variable names. A variable name must be a single continuous string without spaces.
S.I. — This is an invalid variable name because it contains full stops, which are not allowed in variable names. Variable names can only include letters, digits, and underscores.
volume — This is a valid variable name.
tot_strength — This is a valid variable name.
#tag — This is an invalid variable name because it starts with a hash symbol (#), which is not allowed in variable names. Variable names must start with a letter or underscore.
tag — This is an invalid variable name because it contains a dollar sign (), which is not allowed in variable names. Variable names can only include letters, digits, and underscores.
9a — This is an invalid variable name because it starts with a digit, which is not allowed in variable names. Variable names must start with a letter or underscore.
for — This is an invalid variable name because
for
is a reserved keyword in Python and cannot be used as a variable name.
Answered By
3 Likes
Related Questions
Evaluate the following expressions manually:
(a) (2 + 3) ** 3 - 6/2
(b) (2 + 3) * 5//4 + (4 + 6)/2
(c) 12 + (3 * 4 - 6)/3
(d) 12 + (3 ** 4 - 6)//2
(e) 12 * 3 % 5 + 2 * 6//4
(f) 12 % 5 * 3 + (2 * 6)//4
Evaluate the above expressions by using IDLE as a calculator and verify the results that you get manually.
Find the output of the following code:
x=3 y=x+2 x+=y print(x,y)
Find the output of the following code:
x=-2 y=2 x+=y y-=x print (x,y)