The CTP Book

A book for teaching Computational Thinking and Programming skills to people with a background in the Humanities

View on GitHub

Understanding - Beginner, exercise 13

Text

Consider the following Python function:

def f(s):
    if len(s) > 3:
        return s[3:]
    else:
        return s[:3]

What is the result of the execution of f("bod")?

Solution

"bod"

Additional material

The runnable Python file is available online. You can run it executing the command python exercise_13.py in a shell.