fbpx

Variables Copy

Variables are names to store data and use in computations. In Python, variables can be a sequence of characters, including special character underscore (‘_ ‘).

Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. Variables can be integers, decimals (Floats), strings and we can also perform calculations and much more inside variables. These can be declared by any name or even alphabets like a, aa, abc, etc.

Example: If “x” is the variable to be declared with a value “10” then we can write the following command:
x=10

Rules for creating variables in Python:

  • A variable name must start with a letter or the underscore character.

  • A variable name cannot start with a number.

  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

  • Variable names are case-sensitive (name, Name and NAME are three different variables).

  • The reserved words(keywords) cannot be used to name the variable.