Python Variables

What is a Variable in Python? 

  • A Python variable is a reserved memory location to store values. 

  • In other words, a variable in a python program gives data to the computer for processing. 

     

    Example :-

                x = 5
                y = "Rahul"
                print(x)
                print(y)

    Example :-

         >>> n = 1000
         >>> print(n)
         1000
         >>> n
         1000

     

Variable Names

  • A variable can have a short name ( x and y) or a more descriptive name.
  •  Rules for Python variables:
        1. A variable name must start with a letter or the underscore character
        2. A variable name cannot start with a number
        3.A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
        4.Variable names are case-sensitive (age, Age and AGE are three different variables)
        5.Variable names are case-sensitive.

Comments