Python Variable

From GM-RKB
Jump to navigation Jump to search

A Python Variable is a software variable in a Python code.



References

2013

  • https://en.wikibooks.org/wiki/Python_Programming/Variables_and_Strings#Variables
    • The interplay between different variables in Python is, in fact, more complex than explained here. The above example works with integer numbers and with all other basic data types built into Python, the behavior of lists and dictionaries (you will encounter these complex data types later) is entirely different though. You may read the chapter on Data Types for a more detailed explanation of what variables really are in Python and how their type affects their behavior.

      However, it is probably sufficient for now if you just keep this in mind: whenever you are declaring variables or changing their values, you always write the name of the variable on the left of the equals sign (the assignment operator), and the value you wish to assign to it on the right.


  • http://www.tutorialspoint.com/python/python_variable_types.htm
    • Python variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.

      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.

      Python allows you to assign a single value to several variables simultaneously. For example: [math]\displaystyle{ a = b = c = 1 }[/math] Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example: [math]\displaystyle{ a, b, c = 1, 2,\ ''john\lt /i\gt }[/math] Here, two integer objects with values 1 and 2 are assigned to variables a and b, and one string object with the value "john" is assigned to the variable c.

      The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard types that are used to define the operations possible on them and the storage method for each of them.

       Python has five standard data types: