PYTHON DICTIONARY
CommentsData typesVariablesIf ElseIf Elif ElseFunctionsFor loopWhile loopData structuresString slicingUser defined functionLocal/Global variableValidation and TryMethodsFile I/OPseudocodeModules |
What is a data structure?
Python challenge - List (or 1d array)Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Here we have two lists. In the last two lines we are displaying an element from each list via their index number in the list. It is important to remember that the first index number (the first position) in a list is always zero. NOTE that a list uses square brackets. Test the code in a code editor to see what happens.
Try 10 multiple choice questions on lists
Loading Python - Lists1
List methodsSome of the functionality of lists (1D arrays)
Python challenge - TupleEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
A tuple works the same way as a list but unlike a list, you can NOT change the values inside a tuple. This is useful for information that will never need to be changed e.g. a tuple containing the days of the week, months of the year or longitude and latitude information. NOTE that a list uses round brackets. Test the code in a code editor to see what happens.
Python challenge - 2D arrayEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
A 2D array is some lists within a list. Typically, the data stored in a 2D array can be viewed as having similar data in columns or rows. In this example, there are three lists in a list called "People". 2D arrays are a way of holding information in a grid.
Python challenge - 2D array and a For loopEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
What do you think this code does? Change any of the number values and see what it does e.g. change the 0 to a 2. Change the myArray[5] [3]=1 to myArray[5] [3]=2.
Looping through a 2D array - explained
Looping through a 2D array
Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Who is the second fastest sprinter in the world as of 2016? This program will tell you using a 2D array and a user defined function.
Creating a 2D array from an empty arrayEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
The array will be printed twice, will each print look different?
|