What are variables in Python? | Python Basics

What are variables in Python?

    Variables in Python can be thought of as containers for storing data values. The value of the data stored in variables, i.e., the value of variables, can change depending upon the program. The variables are created when the values are assigned to them. But note that the keywords can never be used as a variable name. Get the list of keywords here. If you do so, will cause an error in the program that you have made. See the below video to get a better understanding:

    In the above example, you can see that 'and' and 'or' are the reserved keywords. After using them as a variable, caused an error in the program.

The syntax for assigning a variable to the variable is:
variable_name = variable_value

    When you're writing a variable name that has more 1 word, make sure that you put an underscore (_) between the gaps of words. If you don't put an underscore between the gaps, it will cause an error in the program. Check the below video for better understanding:
    Text can also be assigned to the variable by enclosing them in double ("") or single ('') quotes. Example,

    Do note that the variable name are case sensitive. Example, the variable name Hello differs from HELLO. If you don't name the variable name correctly, you'll end up creating another variable. See the below video to understand better:



Conclusion

Summing up all these exceptions, there are few rules to not while naming a variable. Rules for naming a variable:
Rule 1: The name of a variable must start with a letter or an underscore (_).
Example: _hello, Hello, HELLO etc. are accepted. But variable names like 24X, #name, (Name etc. are not accepted.

Rule 2: The variables names can only have alphanumerical characters and underscores.
Example: hello, h_e_l_l_o, hello123, B_2_2 etc. are accepted. But variable names like AG#E, qwerty@ etc. are not accepted.

Rule 3: The variable names are case sensitive.
Example: The variable name age differs from the variable name AGE.

Rule 4: You can't use a reserved keyword for naming a variable.

No comments:

Post a Comment

Also read!

Class 6 Solutions

• Class 7

Class 7 Computer Kips Solutions
Class 7 Gul Mohar English Solutions
English Grammar Class 7
English Writing Skills Class 7
Class 7 Map Pointing Solutions
Class 7 NCERT Civics Solutions
Class 7 NCERT Civics Notes
Class 7 NCERT Civics Extra Questions
Class 7 NCERT Geography Solutions
Class 7 NCERT Geography Notes
Class 7 NCERT Geography Extra Questions
Class 7 NCERT History Solutions
Class 7 NCERT History Notes
Class 7 NCERT History Extra Questions
Class 7 NCERT Maths Solutions
Class 7 NCERT Science Solutions
Class 7 NCERT Science Notes
Class 7 NCERT Science Extra Questions

• Class 8

Class 8 Kips Artificial Intelligence Solutions
Class 8 Gul Mohar English Solutions
English Grammar Class 8
English Writing Skills Class 8
Class 8 Map Pointing Solutions
Class 8 NCERT Civics Solutions
Class 8 NCERT Civics Notes
Class 8 NCERT Civics Extra Questions
Class 8 NCERT Geography Solutions
Class 8 NCERT Geography Notes
Class 8 NCERT Geography Extra Questions
Class 8 NCERT History Solutions
Class 8 NCERT History Notes
Class 8 NCERT History Extra Questions
Class 8 NCERT Maths Solutions
Class 8 NCERT Science Solutions
Class 8 NCERT Science Notes
Class 8 NCERT Science Extra Questions
Class 8 NCERT Science Exemplar
Class 8 NCERT Science MCQs

Class 9 Solutions

• Class 10

Class 10 Kips Artificial Intelligence Solutions
Class 10 NCERT English Solutions
→ Class 10 Map Pointing Solutions
Class 10 NCERT Civics Solutions
Class 10 NCERT Civics Notes
Class 10 NCERT Civics Extra Questions
Class 10 NCERT Geography Solutions
Class 10 NCERT Geography Notes
Class 10 NCERT Geography Extra Questions
Class 10 NCERT History Solutions
→ Class 10 NCERT History Notes
Class 10 NCERT History Extra Questions
Class 10 NCERT Maths Solutions
Class 10 NCERT Science Solutions
Class 10 NCERT Science Notes
Class 10 NCERT Science Extra Questions

• Computer languages
Python Basics

• Extra Activities
Extra Activities

• Extra Knowledge
Extra Information
General Knowledge
Historical Places in India
Latest technology
Physical Sciences
Facts

• Mathematics quick links
Mathematical Terms
Maths Tricks

CONTACT US