Python’s Types of Data

el

Python has five standard types of data:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionary

The number type data is used to store numerical values, this are created when you assign a value to the object.

var1 = 5

var2= 15

Pythons support four different numerical types:

  • int ( signed integers )
  • long ( long integers, they can also be represented in octal and hexadecimal)
  • float ( floating point real values)
  • complex (complex numbers)

Some examples, for a clearer view:

int long float complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32.3+e18 .876j
-0490 535633629843L -90. -.6545+0J
-0x260 -052318172735L -32.54e100 3e+26J
0x69 -4721885298529L 70.2-E12 4.53e-7j

In the other hand we have the String which are a set of values represented inside a quotation mark.  Python allows either pairs of single or double. Subsets of the string can be made by a slice operator ([] and [:]). Every set starts at 0 to -1. You can include the sing (+) to add something else and the (*) to repeat that string a number of times. Here is an example for a better understanding:

string1

The next type is the list, where you will find items separated by commas and inside brackets, you can access to this list like the string but the difference is that it will appear the complete list of the place you chose, not only a letter or a value; also like the previous you can add something with the (+) and repeat the list with the (*) and example:

list1

The tuples are very similar to the lists, but the main difference is that the tuples are enclosed between parenthesis and not brackets as the list, and another main point is that this type cannot be modify/updated. Here is an example, and at the bottom we see that when I try to modify the tuple it says that tuple doesn’t support that:

tuple 1

For last we have the dictionaries that are a relation between a key and a value given to that key, there are enclosed by the braces {}. A key can be almost everything, but are usually numbers or strings, the values can be of any kind. Here is the example:

dictionarie1

The page where I found all this information is this one, if you like to check it, or iif you didn’t understand me :P:

http://www.tutorialspoint.com/python/python_variable_types.htm

That will be all #Pug #Types #Basic #Tec #TC101 #Python

 

Un comentario Agrega el tuyo

  1. this was super simple and helpful

    Me gusta

Deja un comentario