# Python Concepts/Basic data types

Python
Basic data types
· Operators
· Flow control :

## Overview

This page serves as a generalized introduction to the variable types present within Python.

## Types

Though different languages may handle variable types uniquely, most are quite similar. Python variable types, like the rest of the language, are quite simple. Variable types are determined by the value stored within the variable. Unlike most other languages, keywords like "int", "String", or "bool" are not required in Python, as Python supports type inferencing. The most general compatible variable type is chosen.
There are three main categories of variable types in Python (and every other programming language). They are listed below, ordered by increasing complexity.

### Primitive Variables

Primitive variables are the most basic, hence their "primitive" title. They are capable of storing a single value. In Python there are seven primitive variable types, which are listed below.

#### Numeric types
##### int
##### complex

(Note that this represents a single value, not an arithmetic operation!)

#### Sequence types
##### Strings

In Python, there is no "char" variable type. Instead, characters are represented with a string with a length of one.

##### Bytes
### Complex Variable

Types are a category for things within Python with which Python will work. Types are

#### integer

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

#### float

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

#### string

    A set of letters, numbers, or other characters.

#### tuple

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

#### list

    A list without a fixed number of elements. ie x=[1,2,3] note the square brackets, a list.

#### sets

    A set is a unordered collection of unique elements. ie x={1,2,3} python uses curly braces to represent set.

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

## Opening IDLE

First open IDLE and then open a shell. To open the shell look through the menu bar, some have it under windows, and some have their own shell list. Many also have the short-cut F5.
The shell prompts with ">>>" - the following examples are in the shell.

## Integers

Integers are numeric values and can be stored, manipulated, and expressed inside variables without quotes.
Type:
Notice how it returns the number 23.
Type:
You can also perform basic math using integers as well. Type:

## Floats

Floats are real numbers that represent numbers with decimal point and we can perform arithmetic operations as we do with integers. Type the following into the shell:
Now store float using variables:
To check type of variable, type the following:
we can also represent float values using scientific notation:

## Strings

Strings are a type. They are the basic unit of text in Python and all the other types except integers may contain strings. it contains the single or sequence of characters. Type the following into the shell:
>>>"I Love Python"
It will return
'I Love Python'
You can also make a variable refer to a string.
Type:
>>>x = "I Love Python"
Now Type:
>>>x
'I Love Python'
Now Type:
>>>print (x)
I Love Python
The print command prints the value that 'x' stands for on the screen. It removes the quotations. Whenever you type something into a type that isn't an integer, syntax (the commands that you give python, such as print), or variable (such as x just was) you need to put it into quotations. You can use 'single' or "double" quotations. If you wrote parenthesis outside of the quotations you would have made a tuple (the 'u' sounds like 'touch', not 'tooch') instead of a string. You can also call on a single element in a string.
Type either:
>>>print (x[3])
OR
>>>x[3]
o
Now Type either:
>>>print (x[9])
OR
>>>x[9]
t
As you can see the elements are numbered starting with 0 (due to Python using Ordinals).
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| I | | L | o | v | e | | P | y | t | h | o | n |

## Tuples

A tuple is an unchangeable sequence of values. When you typed ('I love Python') you included only one element.
Type:
When you do this you create a tuple with three elements. You can access these elements individually by typing the variable and then, inside brackets directly to the right of the variable, type the number of the element to which you are referring.
Type:
You may think that it is odd that it returned element 2 instead of element 1. Python starts numbering at 0. element 1 = x[0], element 2= x[1], element 3= x[2]. You can also call on the elements in reverse order.
Type:
Python returned element 3 and not element 2 because x[0] and x[-0] are the same:
For numbering in reverse Python begins with -1.
If you used brackets instead of parentheses you would have made a list.

## Lists

A list is a changeable sequence of data. A list is contained by square brackets i.e. [1,2,3]
Type:
The above code changes element number 2 in x. The last thing we learn is dictionaries.

## Sets

Sets are unordered collection of unique values. Sets are represented by using curly braces in python i.e. {1,2,3}
creating set object:
Accessing set elements: we can't access set elements by key or index, but you can access using for loop
Adding elements in set:
Removing set elements:

## Dictionaries

Dictionaries contain a key and a value. { } enclose dictionaries (Note, that you can also construct a set with curly brackets)
Type:
Now Type:
Depending on what IDLE you are using these may be in different order. The reason for the different order is because dictionaries have no order. You cannot type x[0] and be referring to 'key1':'value1' . What you do to refer to a value is type the key.
Type:
Now Type:
The keys stay the same but the values are changeable. You can also only have one occurrence of a key in a dictionary, but you may have the values all be the same.
Type:
Now Type:
The first key is overwritten by the second.
Type:
Now Type:
This example shows that you can create two separate keys with the same value.

## data types quiz

Or take the:
* Basic data types quiz
next: Python Operators
Python
Basic data types
· Operators
· Flow control :