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
python logo

Compound Data Types

Compound Data Type is a data made from collection of various data types like strings, integers, etc. Compound Data Types in Python can be represented by List, Dictionary, Tuple, Set. Tools I can use to work with Compound Data Types are Iterators, For loops, While loops, and other Functions List Using square brackets [ ] The elements are separated by comma Maintain order of the elements Using index to access the elements Mutable, the elements can be change [1, 2, 3, 1, True, "Kei", "Mars", 0....

February 19, 2022 · 1 min · Kei