Python 3 latest code crumbs

If statement

If statement

Jan 16, 2022 by erik

The if statement is a so-called conditional statement. It is followed by an expression that can evaluate to either True or False. If the expression evaluates to True, the block of code that follows is executed. If it evaluates to...

if
Python exception handling with try.. except

Python exception handling with try.. except

Dec 30, 2021 by erik

This is a small assignment from the Python try-except tutorial. Please do the following: 1. Run the code below, notice the file name (it doesn't exist). See what happens. 2. Change the file name in the Python code to myfile.txt...

exceptions
How to reverse a Python list

How to reverse a Python list

Dec 27, 2021 by erik

There are actually three methods you can use to reverse a list: 1. An in-place reverse, using the built-in reverse method that every list has natively 2. Using list slicing with a negative step size, which results in a new...

list
Return a value from a Python function

Return a value from a Python function

Dec 14, 2021 by erik

In this example, we return a value from a Python function....

return functions
Your first program

Your first program

Dec 10, 2021 by erik

This is the interactive version of the example in the Python.land tutorial here....

print functions