You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 02_Day_Variables_builtin_functions/02_variables_builtin_functions.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@
33
33
34
34
## Built in functions
35
35
36
-
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/2/library/functions.html).
36
+
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/3.9/library/functions.html).
<small> First Edition: Nov 22 - Dec 22, 2019</small>
12
+
<small> Second Edition: July - 2021</small>
13
13
</sub>
14
14
15
-
</div>
16
15
</div>
17
16
18
17
[<< Day 4](../04_Day_Strings/04_strings.md) | [Day 6 >>](../06_Day_Tuples/06_tuples.md)
@@ -48,18 +47,18 @@
48
47
49
48
## Lists
50
49
51
-
There are four collection data types in python :
50
+
There are four collection data types in Python :
52
51
53
52
- List: is a collection which is ordered and changeable(modifiable). Allows duplicate members.
54
53
- Tuple: is a collection which is ordered and unchangeable or unmodifiable(immutable). Allows duplicate members.
55
-
- Set: is a collection which is unordered, unindexed and unmodifiable, but you can add new items. No duplicate members.
54
+
- Set: is a collection which is unordered, un-indexed and unmodifiable, but we can add new items to the set. Duplicate members are not allowed.
56
55
- Dictionary: is a collection which is unordered, changeable(modifiable) and indexed. No duplicate members.
57
56
58
-
A list is collection of different data types which is ordered and modifiable(mutable). A list can be empty or it may have different data type items or items
57
+
A list is collection of different data types which is ordered and modifiable(mutable). A list can be empty or it may have different data type items.
59
58
60
59
### How to Create a List
61
60
62
-
In python we can create lists in two ways:
61
+
In Python we can create lists in two ways:
63
62
64
63
- Using list built-in function
65
64
@@ -218,9 +217,9 @@ orange_and_lemon = fruits[::2] # here we used a 3rd argument, step. It will take
218
217
```py
219
218
fruits = ['banana', 'orange', 'mango', 'lemon']
220
219
all_fruits = fruits[-4:] # it returns all the fruits
221
-
orange_and_mango = fruits[-3:-1] # it does not include the last index
222
-
orange_mango_lemon = fruits[-3:] # this will give the same result as the one above
223
-
reverse_fruits = fruits[::-1] # a negative step will take the list in reverse order
220
+
orange_and_mango = fruits[-3:-1] # it does not include the last index,['orange', 'mango']
221
+
orange_mango_lemon = fruits[-3:] # this will give starting from -3 to the end,['orange', 'mango', 'lemon']
222
+
reverse_fruits = fruits[::-1] # a negative step will take the list in reverse order,['lemon', 'mango', 'orange', 'banana']
Checking an item if it is a member of a list using *in* operator. See the example below.
243
+
243
244
```py
244
245
fruits = ['banana', 'orange', 'mango', 'lemon']
245
246
does_exist ='banana'in fruits
@@ -250,7 +251,7 @@ print(does_exist) # False
250
251
251
252
### Adding Items to a List
252
253
253
-
To add item to the end of an existing list we use the method
254
+
To add item to the end of an existing list we use the method*append()*.
254
255
255
256
```py
256
257
# syntax
@@ -268,7 +269,7 @@ print(fruits)
268
269
269
270
### Inserting Items into a List
270
271
271
-
Use insert() method to insert a single item at a specified index in a list. Note that other items are shifted to the right.
272
+
We can use *insert()* method to insert a single item at a specified index in a list. Note that other items are shifted to the right. The *insert()* methods takes two arguments:index and an item to insert.
The del keyword removes the specified index and it can also be used to delete items within index range. It can also delete the list completely
328
+
The *del* keyword removes the specified index and it can also be used to delete items within index range. It can also delete the list completely
328
329
329
330
```py
330
331
# syntax
@@ -347,7 +348,7 @@ print(fruits) # This should give: NameError: name 'fruits' is not defined
347
348
348
349
### Clearing List Items
349
350
350
-
The clear() method empties the list:
351
+
The *clear()* method empties the list:
351
352
352
353
```py
353
354
# syntax
@@ -363,7 +364,7 @@ print(fruits) # []
363
364
364
365
### Copying a List
365
366
366
-
It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list2. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way avoid the problem above is using _copy()_.
367
+
It is possible to copy a list by reassigning it to a new variable in the following way: list2 = list1. Now, list2 is a reference of list1, any changes we make in list2 will also modify the original, list2. But there are lots of case in which we do not like to modify the original instead we like to have a different copy. One of way of avoiding the problem above is using _copy()_.
🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
527
+
🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
0 commit comments