Variable Types

--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:

Variabletypes1

and the outcome is:Variabletypes2

 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.

Variabletypes

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.

Variabletypes3

and the outcome is:

Variabletypes4

List:

A list contains different data types, you can access to a list stored value using the slice operator “[]” and “[:]”.

For example:

Variabletypes5

and the outcome is:

Variabletypes6

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:

Variabletypes7

So the outcome would be:

Variabletypes7

Dictionaries:

Dictionaries consists in a key-value match, you can join the key

Variabletypes9
Variabletypes10
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:

Variabletypes9

And this is what python will do:

Variabletypes10