Code In Your Browser Window

HTML, Python, JavaScript + Projects

In partnership with

This week we’re rolling out two new (free) tools for coders and sharing the latest job opportunities. Look out for Python projects and portfolio challenges for web developers.

This Week’s Resources

Partner Offer

The Daily Newsletter for Intellectually Curious Readers

  • We scour 100+ sources daily

  • Read by CEOs, scientists, business owners and more

  • 3.5 million subscribers

New Code Editors

Have you ever wanted to try your code while you’re researching it on Hackr? We know the feeling.

That’s why we rolled out our new (free) HTML, CSS, and JavaScript editors directly on our project pages.

You can find these embedded into our project pages. Here are a few HTML Projects (with source code) you can try right now.

Note that we’ve also rolled out our new Python compiler in some places, too.

What Is A Python List?

Beyond its basic function as a collection of items, the Python list is a powerful, mutable, and versatile data structure.

At its core, the Python list is an ordered collection of items, where each item can be of any object type. This makes lists one of the most versatile and commonly used data structures in Python. But what is a list? Is it a data type, a data structure, a sequence, or an interable?

The short answer is, yes, it’s all of these! And whatever Python project you’re working on, chances are, you’ll be using a list. Let’s explore some more.

The Big Benefit of Lists: Mutability

Mutability refers to the ability of an object to change its state or content after its creation. When we say Python lists are mutable, it means you can alter their contents by adding, removing, or updating elements without the need to create a new list.

'''
Hackr.io Guide To Python Lists:
Mutable Property
'''
fruits = ['apple', 'banana', 'cherry']
print(f'Original List: {fruits}') 
# Output: Original List: ['apple', 'banana', 'cherry']

fruits[0] = 'grape'  # Changing the first element
print(f'Modified List: {fruits}') 
# Output: Modified List: ['grape', 'banana', 'cherry']

How to Use Github Copilot: Video

Switch Statements in Python?

A switch case statement is a multi-branched statement that compares the value of a variable to the values specified in the cases. Python does not have a switch statement but it can be implemented using other methods, which will be discussed below.

So how do you accomplish the same goal in Python?

Here’s one way: Use a dictionary.

def my_function(argument):
    switcher = {
        0: "This is Case Zero",
        1: "This is Case One",
        2: "This is Case Two"
    }
    return switcher.get(argument, "nothing")

# Example usage
print(my_function(0))  # Output: This is Case Zero
print(my_function(1))  # Output: This is Case One
print(my_function(2))  # Output: This is Case Two
print(my_function(3))  # Output: nothing

Looking for a Job?

If you’re looking for job opportunities, be sure to check out the latest options on our job board.

Rate this Newsletter

The team at Hackr.io aims to provide the best information possible. Please let us know how we're doing!

Login or Subscribe to participate in polls.