python logo

Iterators - For Loop

I can use For loop and While loop for Iteration. They basically do about the same thing but the preferred method is using a For loop. For loop is typically use when iterating over a sequence of values (like a list or dictionary). Examples of Iteration using For loop: some_nums = [2, 4, 88, 99, 101] for num in some_nums: print(num) This will get the sum of all the integers value in a list :...

March 20, 2022 · 3 min · Kei
python logo

Tuples

Tuples using parentheses ( ) Example of Tuples mixed_tuple = ("mars", 11, 13, 99, "pluto", 81, 30, "venus") tup_str = ("pertama", "kedua", "ketiga") print(mixed_tuple) print(type(mixed_tuple)) print(tup_str) print(type(tup_str)) To list all the built-in methods and functions available for Tuple, I can use dir() mixed_tuple = ("mars", 11, 13, 99, "pluto", 81, 30, "venus") print(dir(mixed_tuple)) Tuple works similar like List, except that Tuple is immutable....

February 23, 2022 · 1 min · Kei