Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/dict.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions src/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ 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
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
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')
```
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
```
14 changes: 7 additions & 7 deletions src/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ 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'
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 (",")
```
Expand Down
6 changes: 3 additions & 3 deletions src/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ 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)
tuple_list [1] = 'b'
example_tuple = tuple(tuple_list)
```

### Unpack
## Unpack

```python
(x, y, z) = example_tuple
Expand Down