How to define variable in python?

Python Variables

A variable is a named location used to store data in the memory. Variable is a user define name that is used to refer to memory location. Python variable is also known as an identifier and used to hold value. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. you should always use lowercase letters for the variable name. Sana and sana both are two different variables.

  • All the characters except the first character may be an alphabet of lower-case(a-z), upper-case (A-Z), underscore, or digit (0-9).
  • when you declare variable the first character of the variable must be an alphabet or underscore ( _ ).
  • The equal sign (=) is used to assign values to variables.
  • variable name must not contain any white-space, or special character (!, @, #, %, ^, &, *).
  • variable name must not be similar to any keyword defined in the language.
  • variable names are case sensitive; for example, my name, and MyName is not the same.
  • Examples of valid identifiers: a123, _n, n_9, etc.
  • Examples of invalid identifiers: 1a, n%4, n 9, etc.
  • File Name : Example

    number = 5
    website = "ittutorial.in"
    print(website)

    variable declaration

    File Name : ittutorial example

    name = "Sana Mahtab"
    father_name = "Mahtab Habib"
    age = "2"
    print("My name is: ", name, )
    print("My Father name is: ", father_name, )
    print("My age is: ", age)

    Multiple Assignment

    a = b = c = 1

    a,b,c = 1,2,"john"

    Python Float initialize :-

    x = 20.85669842
    y = -0.0000000008566945
    print(x)
    print(y)

    Object References

    Python is the highly object-oriented programming language; that's why every data item belongs to a specific type of class.

    print("Arham Kalam")

    The Python object creates an integer object and displays it to the console. In the above print statement, we have created a string object. type("Kashaf Kalam") function





    Previous Next


    Trending Tutorials




    Review & Rating

    0.0 / 5

    0 Review

    5
    (0)

    4
    (0)

    3
    (0)

    2
    (0)

    1
    (0)

    Write Review Here