martes, 27 de octubre de 2015

Mastery 9 - Basic types

Here im going to prove that i know the basic types of Python.

- Integers

 An integer number
x = 7
x + 3 = 10
It canbe used for calculations

- Floats

It´s a decimal number
x = .7 
1.4456
0.1234

- Strings

Is a word, you need to tell pyhton that you are writing a string and not a variable with "
x = "Hello World"
It can be added to integers and other strings
print (x,"I´m jose carlos and im",18,"years old")
Hello World I´m jose calros and im 18 years old

-Tuples

An uneditable list, to make one you need to use parenthesis
x = (1,2,3)

-Lists

A list that can me edited, to make one you need to use brackets
x = [6,1,9,"hola","hello"]

-Dictionaries 

You link elements with other type, you create one with {} and link each element with :, it is comonly used to map strings to integers.
x = {"hola":1,"jose":2, 15:15,"new word":0}

You can modify the type of a variable with preset functions, sometimes it doesnt work
x = 12
str(x)
"12"
x = "hola"
int(x)
Error

No hay comentarios:

Publicar un comentario