The variables in the Python programming language

Variables are an important part of any program. Depending on the programming language variables may be defined in some way. However, please note that there is virtually no program without variables. To write quality code in Python, you must be able to work with variables and know some of the subtleties.

What is a variable? - This name. This name we can assign any information. The important point is that in Python is no strict instructions types. This means that the declaration we do not need to specify the type of the variable. Attempts to declare a variable in a C-like languages simply cause a compilation error, and the program will not work. How to declare a variable? Everything is quite simple:

a = 5

Example integer variable "a" is set to 5. On the other hand, this does not mean that only a may be an integer type. If after the announcement finish line "a = 6.5", then the variable will be a real type, and so on. To display the information in Python is ideal built-in function "print". If necessary, you can easily display the value of a variable on the screen as follows:

print (your variable name)

An important role is played by the variable name. Python is case-sensitive language, which means that "a" and "A" are different variables and are stored in different memory locations. It is also important to know that the variable name can only contain letters digits and the underscore (_). The variable name can not start with a number, as this will result in a compile error.

It is important to remember how you called a variable. When referring to an undeclared variable error occurs. You can easily verify this fact in practice. To remove variables, you can use built-in "del" with the following syntax:

del name of your variable

After calling the function del you will not be able to turn to its variable and you have to re-assign it a new value.


17 February 2017

You may be interested in