--Originally published at Ed_Alita
The informatic language as in real life they have like languages but in Python they are call Variable Types. This types are determine by the value stored within the variable. In other languages you need to put the type before the variable as example “boolean” but in Python supports type inferencing. The most general compatible variable type choosen.
They are three main categories of variable types in Python.
Primitive Variables
Primitive variables are the most basic, hence their “primitive” title. They are caple of storing a single variable. There is list of primitive variable below.
Integers
Numbers such as 23 or -44
Floats
Very little numbers such as 4.3356
Strings
Phrases such as “Python” (Note all letters need to be enclosed by ” ” )
Characters
One letter such as “A” or “#”
Complex Variables
Tuples
A list of Fixed number of elements. Ex. x=(1,2,3)
Lists
A list without a fixed number of elements. Ex. x=[1,2,3]
Dictionaries
A type with multiple elements where you address the elements with a text.
Ex. x={1:’a’,2:’b’,3:’c’}
Use of Them
Integers
This is how to code with Integers.
The result of this is the next one:
Note that you can do Arithmetic with integers.
Strings
The result of this is the next one:
Tuples
This create a tuple with three elements. Also you can print them with this code.
The result of this is this:
Also you can print a specific element of the turples. With the next code:
The result of this code is the next one:
The question that you may have is why is priting the second element if I put that the 1 element is needed to be print it. The reason of this is that python start numering by the cero therefore element1 = 0, element2 = 1 and
= 2.Also you can call the elements in reverse order. For Example:
The result is:
List
The code to make a list id the next one:
The result:
Also you can exhange elements between the list of elements. For Example
The result
Dictionaries
The code to create one is the next one:
The result is the next one:
Also you can exhange or add to the dictionary. In this case I will show you how to exhange, but in the case of adding you anly put a different key by the ones ypu already had.
The result
All the info of this post can be seen at this link
https://en.wikiversity.org/wiki/Python/Basic_data_types#quiz0
Sorry fot the long post, here is a dancing potato