Variables are containers for storing data values.



Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.

Properties of variables:

  • Variables do not need to be declared with any particular type, and can even change type after they have been set.
Code:


  • If you want to specify the data type of a variable, this can be done with casting.
Code:



  • You can get the data type of a variable with the type() function.
Code:


  • String variables can be declared either by using single or double quotes.
Code:


  • Variable names are case-sensitive.
Code:


Rules for Python Variables:

  • 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 (ajblogs, AJBlogs and AJBLOGS are three different variables)