Tag Archives: #quiz0

#mastery09 Basic types and their use in Python

Types are a category for things within Python with which Python will work. Types are integers,float,strings,tuples,lists and dictionaries.

Integers 

Whole numbers from negative infinity to infinity, such as 1, 0, -5, etc.

Integers are numeric values and can be stored, manipulated, and expressed inside variables without quotes.

Example: 

x=5

print (x)

>>>5

Float

Short for “floating point number,” any rational number, usually used with decimals such as 2.8 or 3.14159.

Strings 

A set of letters, numbers, or other characters.

Strings are a type. They are the basic unit of text in Python and all the other types except integers may contain strings.

Example:

x=”Hello World”

print (x) 

>>>Hello World

Tuples 

A list with a fixed number of elements. ie x=(1,2,3) parentheses makes it a tuple.

A tuple is an unchangeable sequence of values.

Example:

x = (“element 1”, “element 2”, “element 3”)

Lists

A list is a changeable sequence of data. A list is contained by square brackets i.e. [1,2,3]

Example:

x=[1,2,3]

print (x)

>>>[1,2,3]

Dictionaries 

A type with multiple elements i.e. x = {1: ‘a’,’b’: 2,3: 3} where you address the elements with, e.g., a text.

Example:

x={‘Hello’:’hola’, ‘Bye’:’adios’}

 

print(x)

>>> {‘Hello’:’hola’, ‘Bye’:’adios’}

Source with more info.: http://en.wikiversity.org/wiki/Python/Basic_data_types#quiz0

1014

09

Gilberto Rogel García