Skip to main content

Getting started with Python

Port Vila, Vanuatu

Hello World

print('Hello World')

User Input

user_says = input ('Please enter a string: ')

print(user_says)

user_says is a Python variable that is used to store data, in this case it is assigned the string from the input function. We can then print out the variable to see if it worked.

Variables

Python

Data Types

  • mutable data type
    • lists
    • dictionaries
    • sets
  • immutable data types
    • strings
    • numbers
    • tuples
    • frozensets

Strings

Python

Python

Python

Python

Numbers

Python

Booleans

Python

Lists

Python

Python

Python

Set

Sets = unordered lists of unique items.

Python

You can create a set from a list to remove duplicates.

Python

Python

Python

Just as list before sets are mutable - you can add or remove elements at will. To create an immutable set from a list you have to use FrozenSets:

Python

Tuples

Tuples are immutable list - elements cannot be added or removed once the tuples was created.

Python

Tuples allow you to map values to variables by assigning a tuple, made up of variables, to a tuple, made up of values:

Python

Ranges

Python

Dictionaries

Dictionaries are an unordered list of key-value pairs. Every key has to be unique and should be of an immutable type - strings, numbers or tuples.

Python

Conversion between Data Types

Python

Python