Photo by Malkarium on Unsplash

There are three keywords required to declare variables: let, const, and var.

let

When using let, you declare block-level variables. This means the declared variable will be available in the block it’s declared in. For example:

let cat = 'Mufasa';// Between the curly brace is the block scopefunction catName() { // Start of the block scope
console.log("catName:", cat);
}; // End of the block scope
function catRenamed() {
let cat = 'Scar'; // You can re-declare variables with the keyword let in different scopes
console.log("catRenamed:", cat);
}
catName();
catRenamed();
console.log(cat); // What does this log out?

You can change…


Photo by Free-Photos from Pixabay

Basic For Loop Syntax

for (index; condition; increment/decrement) {
// body of the loop
}

The index is used to compare against the condition. The condition is used to check the loop at every iteration and will continue to run as long as it evaluates to true. The increment/decrement is used to increase or decrease the value of index. The order of where you place each of them (index; condition; increment/decrement) is fixed.

The for loop is often used to repeat a specific block of code a known number of times. For example:

for (let i = 0; i < 5; i++) { console.log(i)…

Photo by Tyler Nix on Unsplash

Basic Syntax of Filter

const newArray = array.filter(item => {
return condition;
});

The item will be used to reference the current element in the array against the given condition. If the current element in the array passes, then it will be stored in a new array which, in this case, is called newArray.

Using filter()

Just to reiterate, filter() is an Array method that creates a new array with values that depend on the criteria you give it. For example:

const prices = [10, 20, 30, 40, 50, 60, 70];const newPrices = prices.filter((price) => {
return price > 40;
});
console.log(prices) // [10, 20…


Photo by Brooke Lark on Unsplash

How should you style your code?

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…


Photo by Joshua Hoehne on Unsplash

This is a summary of Chapter 6 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

What is a Dictionary?

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…


Image by congerdesign from Pixabay

This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

Slicing a List

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. …


Image by Arek Socha from Pixabay

This is a summary of Chapter 5 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

What is an If Statement?

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!") …


Image by Jose Antonio Alba from Pixabay

This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

Tuples

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"…


Photo by Andrew Buchanan on Unsplash

This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

Using the range() Function

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. …


Photo by Tine Ivanič on Unsplash

This is a summary of Chapter 4 of “Python Crash Course: A Hands-On, Project Based Introduction to Programming” by Eric Matthes

Looping through a List

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…

Aldrin Caalim

Learning is neat.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store