Python Variables

Updated: May 18, 2020


Variables are used to store data and take memory space based on the type of value we assigning to them. We create variables in Python is simple, we write the variable name on the left side of = and the value on the right side. We do not have to openly mention the type of the variable, python gather the type based on the value we are assigning. There are some rules for creating variables in Python.


  • The name of the variable must always start with either a letter or an underscore (_).

  • The name of the variable cannot start with a number like 2num is not a valid variable name.

  • The name of the variable cannot have special characters such as %, $, # etc, they can only have alphanumeric characters and underscore (A to Z, a to z, 0-9 or _ ).

  • Variable name is case sensitive in Python which means num and NUM are two different variables in python.


Python Variable Example

num = 100

str = "Rajesh"

print (num)

print (str)


Output:

100

Rajesh



11 views0 comments

Recent Posts

See All

Tell () function can be used to get the position of file handle and returns current position of file object where as Seek () function is used to change the position of the file handle to a given speci

Seek () function is used to change the position of the file handle to a given specific position in python. File handle such as a cursor which defines from where the data has to be read or written in t