Mastery09. Basic Types in Python and their use

Data-types are different types of ways we can store data. The most basic Data-types are the numbers (which we can divide in integers and Floating point numbers) and strings.

Numbers:

>>>An integer is a whole number form the range of negative infinity to infinity, e.g., -5, 0, 17, etc.

>>>A floating point number is any number that has digits after a decimal point, e.g., 2.4, 132.8441, 3.333, etc.

Strings:

A string is a piece of text that can be a set of letters, numbers or other characters. To include a string in our program, we have to sorround it with quotes or double quotes. e.g.:

>>> x= “This is a string with double quotes”

>>> y= ‘This is a string with simple quotes’

And the work exactly the same.

 

There are some more complex Data-types such lists, tuples and dictionaries.

Lists:

A list stores a bunch of values and keeps them in order for the user; the user can add, delete or modify any item from the list whenever he wants. A list doesnt have a fixed number of values, the user can modify it as he wants. Lists are characterized because of the square brackets. For example:

x=[1,2,3,4,5]

Tuples:

Tuples are a lot like lists but the do have a fixed number of values that can not be modified. Different from lists, tuples are defined with parentheses instead of square brackets. For example:

x=(1,2,3,4,5)

Dictionaries:

Dictionaries contain a key and a value, so ypu can look up for the value later using the key. We can use dictionaries to build complex nested data structures or just to store values. The syntax is the following:

x={‘key1’: ‘value1’, ‘key2’: ‘value2’}

 

You can learn more about data-types in here: http://www.voidspace.org.uk/python/articles/python_datatypes.shtml

 

CC BY 4.0 Mastery09. Basic Types in Python and their use by Manuel Madrigal is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.