5. Identify invalid variable names from the following, give reason for each:
Group, if, int, total marks, S.I., volume, tot_strength, #tag, tag$. 9a
this question is rated to python programming.
please answer fast
if u will give correct answer of my question then I will definitely follow u.
Answers
Answer:
if, int,total marks, !_volume,Tag@, 9a,S.I. are invalid
Explanation:
if - it is a keyword.
int - it is a keyword.
total marks - has a space.
!_volume - has an invalid character -!
Tag@- has an invalid symbol.- @
9a - has a number.
S.I. - has dots.
The invalid variable names are if, int, total marks, S.I., #tag, tag$, and 9a
Let's correct the question
Identify invalid variable names from the following and give the reason for each:
Group, if, int, total marks, S.I., volume, tot_strength, #tag, tag$, 9a
Explanation
1. Group
This variable name is valid as it starts with a letter and contains alphanumeric characters.
2. if
This variable name is invalid since if is a keyword.
3. int
This variable name is invalid since int is a keyword.
4. total marks
This variable name is invalid since it contains space.
5. S.I.
This variable name is invalid since it contains dots(.)
6. volume
This variable name is valid since it contains alphanumeric characters.
7. tot_strength
This variable name is valid since it contains alphanumeric characters and underscore(_).
8. #tag
This variable name is invalid since it contains a hash symbol (#).
9. tag$
This variable name is invalid since it contains a dollar symbol ($)
10. 9a
This variable name is invalid since it starts with a number.
Extra Information
Rules for variables/identifiers in Python language
1. Variable/Identifier name can start with a letter or underscore ( _ ) character only. It cannot start with a digit.
2. Python is a case-sensitive language which means variable/identifiers names are also case-sensitive.
Example - These three are different variables age, AGE, Age
3. Variable/Identifier names can only have alphanumeric characters (A-Z, a-z, and 0-9) and underscore ( _ )
Variable can be short or long/descriptive.
Example - x, y, z, age, gender, Address, _var, etc.
Note - Variable names can't have whitespaces, special characters such as !, #, %, etc. and variable names can't be a keyword that is reserved such as float, int, true, false, none, etc.
What is case sensitivity?
Case sensitivity is the term that tells us about the programming language capability of making out differences between Upper Case Letters(A, B, C, and so on) and Lower Case Letters (a, b, c, and so on).
Python is created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.