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
- Casting: Converting one data type to another data type. We use _int()_, _float()_, _str()_, _list_, _set_
209
209
When we do arithmetic operations string numbers should be first converted to int or float otherwise it will return an error. If we concatenate a number with a string, the number should be first converted to a string. We will talk about concatenation in String section.
210
210
211
-
**Example:**
211
+
**Examples:**
212
212
213
213
```py
214
214
# int to float
@@ -229,8 +229,10 @@ print(num_str) # '10'
229
229
230
230
# str to int or float
231
231
num_str ='10.6'
232
-
print('num_int', int(num_str)) # 10
232
+
num_float =float(num_str)
233
233
print('num_float', float(num_str)) # 10.6
234
+
num_int =int(num_float)
235
+
print('num_int', int(num_int)) # 10
234
236
235
237
# str to list
236
238
first_name ='Asabeneh'
@@ -281,13 +283,13 @@ Number data types in Python:
281
283
1. Using the _len()_ built-in function, find the length of your first name
282
284
1. Compare the length of your first name and your last name
283
285
1. Declare 5 as num_one and 4 as num_two
284
-
1. Add num_one and num_two and assign the value to a variable total
285
-
2. Subtract num_two from num_one and assign the value to a variable diff
286
-
3. Multiply num_two and num_one and assign the value to a variable product
287
-
4. Divide num_one by num_two and assign the value to a variable division
288
-
5. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder
289
-
6. Calculate num_one to the power of num_two and assign the value to a variable exp
290
-
7. Find floor division of num_one by num_two and assign the value to a variable floor_division
286
+
1. Add num_one and num_two and assign the value to a variable total
287
+
1. Subtract num_two from num_one and assign the value to a variable diff
288
+
1. Multiply num_two and num_one and assign the value to a variable product
289
+
1. Divide num_one by num_two and assign the value to a variable division
290
+
1. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder
291
+
1. Calculate num_one to the power of num_two and assign the value to a variable exp
292
+
1. Find floor division of num_one by num_two and assign the value to a variable floor_division
291
293
1. The radius of a circle is 30 meters.
292
294
1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_
293
295
2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_
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()_.
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, list1. 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()_.
368
368
369
369
```py
370
370
# syntax
@@ -562,7 +562,7 @@ To sort lists we can use _sort()_ method or _sorted()_ built-in functions. The _
562
562
back_end = ['Node','Express', 'MongoDB']
563
563
```
564
564
565
-
27. After joining the lists in question 26. Copy the joined listand assign it to a variable full_stack. Then insert Python andSQL after Redux.
565
+
27. After joining the lists in question 26. Copy the joined listand assign it to a variable full_stack, then insert Python andSQL after Redux.
It returns the the symmetric difference between two sets. It means that it returns a set that contains all items from both sets, except items that are present in both sets, mathematically: (A\B) ∪ (B\A)
346
+
It returns the symmetric difference between two sets. It means that it returns a set that contains all items from both sets, except items that are present in both sets, mathematically: (A\B) ∪ (B\A)
350
347
351
348
```py
352
349
# syntax
@@ -383,7 +380,7 @@ st2.isdisjoint(st1) # False
383
380
384
381
```py
385
382
even_numbers = {0, 2, 4 ,6, 8}
386
-
even_numbers= {1, 3, 5, 7, 9}
383
+
odd_numbers= {1, 3, 5, 7, 9}
387
384
even_numbers.isdisjoint(odd_numbers) # True, because no common item
1. Explain the difference between the following data types: string, list, tuple and set
428
425
2._I am a teacher and I love to inspire and teach people._ How many unique words have been used in the sentence? Use the split methods and set to get the unique words.
429
426
430
-
431
427
🎉 CONGRATULATIONS ! 🎉
432
428
433
429
[<< Day 6](../06_Day_Tuples/06_tuples.md) | [Day 8 >>](../08_Day_Dictionaries/08_dictionaries.md)
0 commit comments