#3 Python Glossary : Variable
We have not to find meaning every word in python code. Some of them
If we write or read python script, variables often appear. A variable is a container that represents data that we know or we decide it later. in algebra, a variable is a symbol for a number we don’t know yet. It is usually a letter like x or y. In Python, the variable is represented numbers, word, and lists that we already assign or we will assign later.
Compare to spreadsheet like excel, python variable is like cell. Cell is empty container that we can decide value later. Python variable is a reserved memory location. Variable is place that we can store values.
Form of variable in python is:
- user-defined alphabet or word. The programmer defines a variable name, so find reference of the word is not necessary. So, a programmer can define a variable: var1, dido,
doli, bubu, this_is_variable, and so on.
- a variable name has no spaces.
- start with a letter or underscore. We can not write a variable that starts with numbers. So, this example that is allowed: yoyo1, y4_ya, y1yi, et cetera. This is the example that not allowed: 1ya, 2yoyo et cetera.
- consist one or more under case letter, underscore and number. We can not put a number in the first alphabet, but we can put it in a second or more position. For example my_variable, energy_var1, and so on.
- Some of the words are python word that has specifics function. So we can not use 33 python keywords as a variable. They have another use in python. Python 33 keywords
False. class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, is: elif, if, or, yield, assert, else, import, pass, break, except, in, raise.
- we can assign variable by using “=”. For example my_variable = 10
- a variable is unique. We can not have two variables that have the same name. Python read it as
samevariable. Python read laststatement as a valid value of the variable. You can see the example below.
>>> my_variable = 10 >>> print my_variable 10 >>> my_variable = 11 >>> print my_variable 11
- A variable can contain number, text (string), or list (set of data).
- To assign text to a variable, we have to give quotation
mark beforeand after text . Wecan assign variable with setof datalist. For example, we have a variable that has named my_book. It can contain a set of data.
>>> my_book =['python for beginner', 'dive to python', 'business'] >>> my_text_variable = 'it is text'