Python: While Loops

Python

This is post 25 of 30 in the series “Introduction to Python” Go to Chapter 51 of A Smarter Way. Recall for loops: http://gnorman.org/2018/10/02/python-for-loops/ for friend in friends: print(“Hello, ” + friend.title() + “!”) For loops are good for meeting a single condition, once. But sometimes you need to keep performing the matching operation. This …

Python: Nested for Loops

Python

This is post 21 of 30 in the series “Introduction to Python” Go to Chapter 22 in A Smarter Way. You can put a for-loop inside another for-loop: first_names = [“Bill”, “Joel”, “Jeff”, “Jim”] last_names = [“E-boy”, “E-man”, “Jefferson”, “O’theJungle”] full_names – [ ] for a_first_name in first_names:     for a_last_name in last_names:         full_names.append(a_first_name …

Python: for Loops

Python

This is post 20 of 30 in the series “Introduction to Python” Go to Chapter 21 of A Smarter Way. Remember an earlier for loop we used: friends = [‘bill’, ‘jeff’, ‘jim’] for friend in friends: print(“Hello, ” + friend.title() + “!”) Often we use these inside if-tests: friends = [‘bill’, ‘joel’, ‘jeff’, ‘jim’, ‘scott’, …

Python: Tuples

Python

This is post 19 of 30 in the series “Introduction to Python” Go to Chapter 20 of A Smarter Way. A tuple is like a list, but its elements cannot be changed once they’re defined. In a list we used square brackets to define the list: friends = [‘bill’, ‘jeff’, ‘jim’, ‘scott’, ‘joel’] By contrast, …

Python: Lists: Take a Slice, Delete Elements, Popping Elements

Python

This is post 18 of 30 in the series “Introduction to Python” Go to Chapter 17 of A Smarter Way. Return to our lists page: http://introtopython.org/lists_tuples.html#Want-to-see-what-functions-are? …and scroll down slightly because the page TOC is (again) broken. Taking a slice from a list: friends = [‘bill’, ‘jeff’, ‘jim’, ‘scott’, ‘joel’] # Grab the first three …