Python Language Lesson: variable
A variable is a name that refers to a value. In Python you do not haveto declare variables, that is, you do not have to specify in advance the
type, such as integer, string, and so on. Variables are implicitly typed,
meaning that the type of a variable is the type of the value it refers to.
If your variable holds the integer 5 but you need the string ‘5’, you
have to use the str() function to convert the integer to a string. The
type of a value does not change automatically.
The first time you use a variable, assignment is done with the equals
sign ‘=’. It creates a new variable and gives the variable a value, for
example:
data = 5
mynewlist = "Symbian"
The special value None denotes a missing value. You can re-use the
same variable freely throughout a program.
In some examples, we use capital letters for variable names. This is
a common way in Python to denote variables whose values must not
change (that is, they are constants), as a convenience to developers.
The interpreter itself does not care if they are constant.
No comments:
Post a Comment