Basic data Types

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

technology promotion primitive

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

amor alone lonely hard leaving

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.

integers

The result of this is the next one:

integersEx

Note that you can do Arithmetic with integers.

Strings

string

The result of this is the next one:

stringsEx

Tuples

Turples

This create a tuple with three elements. Also you can print them with this code.

turples1

The result of this is this:

turplesEx1

Also you can print a specific element of the turples. With the next code:

Turples2

The result of this code is the next one:

turplesEx2

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 

turples3
turplesEx3
List1
ListEx1
list2
listEx2
Dictionaries1
DictionariesEx1
Dictionaries2
DictionariesEx2
potato dancing potato
= 2.

Also you can call the elements in reverse order. For Example:

turples3

The result is:

turplesEx3

List

The code to make a list id the next one:

List1

The result:

ListEx1

Also you can exhange elements between the list of elements. For Example

list2

The result

listEx2

Dictionaries

The code to create one is the next one:

Dictionaries1

The result is the next one:

DictionariesEx1

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.

Dictionaries2

The result

DictionariesEx2

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

 

potato dancing potato