In an earlier article, I showed “The Zen of Python, by Tim Peters”. It is considered to be the core philosophy of Python. Here is it once again:
The Zen of Python, by Tim PetersBeautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should…
This is a summary of Chapter 6 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
Dictionaries are used to store data values in key-value pairs. Each key is connected to a value, and you can use a key to access the value associated with that key. A key’s value can be a number, string, list, another dictionary, you can use any object that you created in Python as a value in a dictionary. It’s a collection that is unordered, mutable, and does not allow for duplicates. Dictionaries are written with curly braces and have…
This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
To slice your list, state the index of the first and last elements you are targeting. Just like the range() function, the first value in the slice will be included but the second value will be excluded. For example:
names = ["michael", "dwight", "jim", "kevin", "andy"]
print(names[0:2])>>> ['michael', 'dwight']
As you can see when we slice the list, the first value is included while the second value is excluded. …
This is a summary of Chapter 5 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
If statements allow decision making in code. They check the stated variable and give a designated response. Here is a basic example:
name = "jill"if name == "jill":
print("Hey Jill")
elif name == "john":
print("Hello John")
else:
print("Wait a minute, who are you?")>>> Hey Jill
Here is another example:
for number in range(1, 101):
if number == 7:
print(str(number) + " is my favorite number!")
elif number == 50:
print(str(number) + " is half of 100!") …
This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
Tuples are immutable lists. They look like lists except you use parentheses instead of square brackets. And, just like a list, you can access individual items using the index. For example:
names = ("frank", "john")
print(names[0])
print(names[1])>>> frank>>> john
Like we said earlier, tuples are immutable so let’s see what happens when we try to change anything:
names = ("frank", "john")
print(names[0])
print(names[1])names[0] = "will">>> frank>>> johnTraceback (most recent call last): File "main.py"…
This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
The range() function allows us to generate a series of numbers. For example:
for i in range(0, 3):
print(i)>>> 0>>> 1>>> 2
As you can see from the above code, the code will print the numbers from 0 (inclusive) up until 3 (exclusive). This is the off-by-one behavior you will see a lot in many programming languages. …
This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
Imagine retrieving individual items in a list. If we were to use the print() function, depending on the number of items in the list, it could take forever. We would also have to change our code every time the list’s length changed. For example:
friends = ["kyle", "paul", "chris"]
print(friends[0])
print(friends[1])
print(friends[2])>>> kyle>>> paul>>> chris
The for loop avoids those issues by allowing Python to manage those changes internally. The for loop looks like this:
friends…
This is a summary of Chapter 3 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
A list is a collection of items placed in any order. Lists can be made with all valid data types such as letters, numbers, strings, etc. The items within the list do not need to have any relation, although most tend to create lists based on items that are related to one another. Because lists usually contain more than one item, it’s a good idea to make the name of your list plural, such as numbers, letters, characters, etc.
…
This is a summary of Chapter 2 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes
In Python, a string is a series of characters inside quotes. You can use single or double quotes around your strings like this:
double_quotes = "This is a string with double quotes."
single_quotes = 'This is a string with single quotes.'print(double_quotes)
print(single_quotes)>>> This is a string with double quotes.>>> This is a string with single quotes.
The flexibility to use single or double quotes allows us to use quotes and apostrophes within strings:
as_quote = 'And…
This is a summary of Chapter 2 of “Python Crash Course: A Hands-On, Project-Based Introduction to Programming” by Eric Matthes
print("Hello World")>>> Hello World
The above code is the first program many programmers write when they first start coding. The next step is to add variables:
message = "Hello World"
print(message)>>> Hello World
The above code stores the message “Hello World” into the variable message. Then it is the variable is placed into print and is displays “Hello World”.
message = "Hello World"
print(message)message = "Hello Python"
print(message)>>> Hello World>>> Hello Python
As you see…
Learning is neat.