Please enable JavaScript.
Coggle requires JavaScript to display documents.
Lists within Python, Slicing this is a method to fetch multiple items from…
Lists within Python
The processing and handling of multiple pieces of data can be held in Python lists. This includes: Strings, Tuples, Lists and Dictionaries. These are called Data structures.
Accessing sequenced items this can be done using an index which is the literal position of a part of a list, this is defined as a whole number and is included within square brackets. Positionally number 0 is the first item, you can also use negative numbers to count back from the last value.
In this can be used to output True / False (if using not) based on given variables - For example 'apple' in fruits would return True if 'apple' was in the Fruits list.
not can be used to flip the output - For example 'chicken' "not in" fruits would produce True despite not being in the list
substrings in can also check for the contents of strings called substrings ('ana' in 'banana' is true)
-
-
Tuples are comma separated, immutable groups of given items and are ordered. Tuples are within round brackets and do not need to be the same type. items are to be followed by a comma
-
Lists are ordered and comma separated similarly to tuples but they can be adjusted throughout the program therefore are mutable. Lists are created with square brackets.
Simplest adjustment of a list is to replace a positional item - For example box[2] = 'newvalue' would replace the third box item. We can also use slicing to manipulate a range of items.
-
-
-
-
Stacks are last in first out and Queues are first in first out which would be handled with append rather than pop(0)
-
-
-
Slicing this is a method to fetch multiple items from within a sequence, Slicing is performed like an index but uses multiple integers separated by colons (everything inside of the slice will be outputted). You can also add a third integer to designate the step value (every X).
-