diff --git a/src/dict.md b/src/dict.md index e8cf504..6a97771 100644 --- a/src/dict.md +++ b/src/dict.md @@ -8,7 +8,7 @@ The code below assigns a dictionary to a variable which then can be called and m example_dict = {"one": 1, "two": False, "three": 3, "four": 4} ``` -### Access +## Access There are multiple ways to perform this action, as shown below. @@ -20,7 +20,7 @@ example_dict.values () # Gives a list of values example_dict.items() # Gives a list of items of (keys, values) as tuples ``` -### Change +## Change There are multiple ways to perform this action, as shown below. @@ -29,7 +29,7 @@ example_dict ["two"] = True # Changes the value of key "two" to True example_dict.update ({"four": False}) # Changes the item with the key "four" ``` -### Remove +## Remove There are multiple ways to perform this action, as shown below. @@ -38,7 +38,7 @@ example_dict ["five"] = 5 # Adds a new item of "five":5 to the dictionary example_dict.update ({"six": 6}) # Adds the item to the dictionary ``` -### Looping +## Looping This is used to access every single item or value/key, depending on the iteration loop. diff --git a/src/file.md b/src/file.md index 02555d3..e9a30c0 100644 --- a/src/file.md +++ b/src/file.md @@ -2,17 +2,17 @@ The following code shows how to read, modify and close the files with their particular order. -### Always open the file with read, append or write, modify, then close the file. +## Always open the file with read, append or write, modify, then close the file. ```python example_file = "file-name.txt" ``` -### Opens file and "r" read (error if does not exist), "a" append and "w" write +## Opens file and "r" read (error if does not exist), "a" append and "w" write ```python infile = open(example_file, "r") ``` -### Returns one line, if called twice, it reads first two lines of the file +## Returns one line, if called twice, it reads first two lines of the file ```python infile.readline() infile.close() # closes the file diff --git a/src/lists.md b/src/lists.md index 60b7007..2216329 100644 --- a/src/lists.md +++ b/src/lists.md @@ -8,7 +8,7 @@ The following code assigns a list to a variable, which will then be used to mani example_list = ['a', 1, True, 4, 6, 'b'] ``` -### Access +## Access ```python example_list [-1] # Backwards accessing @@ -16,7 +16,7 @@ example_list [2:5] # Third, Fourth and Fifth item example_list [2:] # Access from third time to the end of the list ``` -### Change +## Change ```python example_list [0] = 'c' # It is not 'a' anymore, it is 'c' for the first element @@ -24,14 +24,14 @@ example_list [1:3] = ['x', 3] # The second and third item are now 'x' and 3 example_list [1:3] = ['r'] # Replaces the range of items with just one item 'r' ``` -### Add/Extend +## Add/Extend -### Without replacing, 'b' slides in between the the second and third item +## Without replacing, 'b' slides in between the the second and third item ```python example_list.insert (2, 'b') ``` -### Adds 'q' to the end of the list +## Adds 'q' to the end of the list ```python example_list.append ('q') ``` @@ -41,12 +41,12 @@ Extend -> extend () works for any iterable objects e.g. tuples, sets, dictionari ```python example_list2 = ['l', 10] ``` -### Adds the entire example_list2 list to the end of the list as elements +## Adds the entire example_list2 list to the end of the list as elements ```python example_list.extend (example_list2) ``` -### Remove +## Remove ```python example_list.remove ('a') # Removes the specific item @@ -55,7 +55,7 @@ example_list.remove ('a') # Removes the specific item `example_list.clear() # Keeps the list empty by removing all elements ``` -### Looping +## Looping ```python # For-Loop for each item diff --git a/src/sets.md b/src/sets.md index 212dfd9..ff1a4a8 100644 --- a/src/sets.md +++ b/src/sets.md @@ -8,7 +8,7 @@ The following code assigns a sample set to a variable, which can then be used to example_set = {1, 'a', True} ``` -### Access +## Access ```python for x in example_set: @@ -17,30 +17,30 @@ for x in example_set: As part of access, you can check if a certain item is in the set, as shown below. -### Check if in list -> Returns True or False +## Check if in list -> Returns True or False ```python check = 1 in example_set ``` -### Add +## Add -### Add Item +## Add Item ```python example_set.add ('b') ``` -### Add two sets ~ update() can be used to any iterable objects +## Add two sets ~ update() can be used to any iterable objects ```python example_set2 = {2, 'c', False} example_set.update (example_set2) ``` -### Remove +## Remove ```python example_set.remove ('a') ``` -### If 'a' does not exist, then discard() does not raise an error +## If 'a' does not exist, then discard() does not raise an error ```python example_set.discard ('a') ``` \ No newline at end of file diff --git a/src/string.md b/src/string.md index b42e0d4..20b0f22 100644 --- a/src/string.md +++ b/src/string.md @@ -8,7 +8,7 @@ The following code assigns a string to a variable, which then can be used to man example_string = "Hello, World!" ``` -### Access +## Access ```python example_string [1] # prints the second element in the string, in this case, 'e' @@ -16,28 +16,28 @@ example_string [2:5] # range example_string [5:] # slice from 6th to end ``` -### Modify -### returns string in all uppercase +## Modify +## returns string in all uppercase ```python example_string.upper () ``` -### returns string in all lowercase +## returns string in all lowercase ```python example_string.lower () ``` -### removes whitespaces from beginning or at the end +## removes whitespaces from beginning or at the end ```python example_string.strip () ``` -### repalces the argument 1 with argument 2 in the original string +## repalces the argument 1 with argument 2 in the original string ```python example_string.replace ("H", "j") ``` -### returns a list with the words being being split at the given argument +## returns a list with the words being being split at the given argument ```python example_string.split (",") ``` diff --git a/src/tuples.md b/src/tuples.md index d666621..5a7269a 100644 --- a/src/tuples.md +++ b/src/tuples.md @@ -8,13 +8,13 @@ The following code assigns a tuple to a variable, which will then be used to man example_tuple = (1, 'a', True) ``` -### Access +## Access ```python example_tuple [1] # access ``` -### Update +## Update ```python tuple_list = list(example_tuple) @@ -22,7 +22,7 @@ tuple_list [1] = 'b' example_tuple = tuple(tuple_list) ``` -### Unpack +## Unpack ```python (x, y, z) = example_tuple