Python - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Python Variables

Python Variables

shape Description

The different memory locations where data resides are called objects. To access such an object it must have a name, and such a named object is called a Variable. The information stored inside an object is called as a value. Of course the machine itself typically has no idea how to interpret the information it contains, but the program certainly needs to know. For this reason a variable has a specific type. And it’s this type that constrains the use of that variable, such that only operations appropriate to the type may be performed. The following is the syntax declaration of the variable in python. [c]variable=value;[/c] The following is an example. [c]a=10;[/c] Where a is the variable.

Assigning values to variables

shape Description

Python factors don't require unequivocal statement to hold memory space. The statement happens naturally when the engineer allocate an esteem to a variable. The equivalent sign is utilized to allot qualities to factors. The following is the image to understand data type declaration. The operand to one side of the = administrator is the name of the variable and the operand to one side of the = administrator is the esteem put away in the variable. The following is an example . [c] splesson = 100 # An integer assignment tutorial = 1000.0 # A floating point name = "Sachin" # A string print splesson[/c] The result will be as follows. [c]100[/c]

Multiple Assignment

shape Description

The following are the ways to define multiple variables in python.

Giving single esteem to multiple variables

The following is an example to understand the terms. [c]a=b=c=50 print a print b print c [/c] Now compile the code result will be as follows. [c] >>> 50 50 50 >>> [/c]

Giving multiple esteems to multiple variables

The following is an example to understand the terms. [c]a,b,c=15,100,150 print a print b print c [/c] Now compile the code result will be as follows. [c] >>> 15 100 150 >>> [/c]

Summary

shape Key Points

  • The variables do not need data types to store a value.
  • The tuples and lists are the some standard data types to represent data.
  • Python is a case sensitive language like Java.