python logo

Iterators - While Loop

While loop can also be use for iteration but while loop is typically use when looping over some condition Example of While loop some_condition = True while some_condition: print("Hello World!") – This code will have an infinite loop, basically it will run forever until the computer crash. It will stop when I hit Ctrl + C to interrupt it, or if there is a break keyword somewhere in the code block....

April 10, 2022 · 1 min · Kei
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

Lists

Lists using square brackets [] Example of Lists int_list = [1, 20, 77, 800, 39, 21, 5] str_list = ["python", "javascript", "java", "rust", "go", "dart"] print(int_list) print(type(int_list)) print(str_list) print(type(str_list)) Some of the things that I could do with lists: Sort the values in ascending or descending order Find values in list or details about the list Insert or remove values from the list Get a sub-list from the list Iterate through the list and perform functions or checks on each list item Some functions that could help me work with lists:...

February 22, 2022 · 4 min · Kei