--Originally published at Sierra's Blog
Variable Types function is to hold the information that your program needs to successfully work, the data you type is stored in a memory.
What are they for?
they are used to store numbers or characters that could be used during the program.
How do I assign a value to a variable?
To assign a variable you must use the (=) sign, and it works this way:
and the outcome is:
Data types:
There variables that you assign in python are saved in an orderly manner, so, data types works as shelves in a library.
Python has 5 standard data types: Numerical, string, list, tuple, dictionary.
Numerical Types:
numerical types are divided in four subcategories:
Int: Integer numbers.
Long: Long integers
Float: Numbers with decimals.
Complex: Complex numbers.
Note: in python 3 long and int numbers merged into just int but before python 3 Long integers numbers used to have a L at the end of the number which indicated that it wasn’t an int.
String:
Strings are gonna divide whatever you type between (”) signs into character, counting from 0 to the last character number.
[] is the operator of the string, * prints the string “x” amount of times, + is the concatenator.
so if I write str [0:10] i’m saying: Hey python! please type the first eleven characters of the string.
and the outcome is:
List:
A list contains different data types, you can access to a list stored value using the slice operator “[]” and “[:]”.
For example:
and the outcome is:
Tuples:
tuples are similar to the list, they work the same but with some differences like that the tuples values are surrounded by (), for example:
So the outcome would be:
Dictionaries:
Dictionaries consists in a key-value match, you can join the key
with the value. Dictionaries are called using this symbol “{}”.This way you can ask python to do anything with: everything you wrote on the dictionarie, the keys, or, the values.
For example:
And this is what python will do: