Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Building Functions | What is a Function in Python?
Python Functions Tutorial
course content

Kursinnhold

Python Functions Tutorial

Python Functions Tutorial

1. What is a Function in Python?
2. Positional and Optional Arguments
3. Arbitrary Arguments
4. Function Return Value Specification
5. Recursion and Lambda Functions

book
Challenge: Building Functions

Let's introduce ourselves. I've written a function that outputs my name, and your task is to write a function that outputs your name.

1234567
# Define the function `say_my_name` def say_my_name(): # The function prints the string `My name is Heisenberg` print('My name is Heisenberg') # Call the function `say_my_name` say_my_name()
copy

The say_my_name function simply prints the phrase 'My name is Heisenberg' to the screen, and we can call this function to see this output.

Oppgave

Swipe to start coding

Write a function that prints your name in the console.

  1. Define a function named print_name.
  2. Inside the function, use print() to output a string with your name in the format: My name is {your name}, where {your name} is replaced with your actual name.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 2
toggle bottom row

book
Challenge: Building Functions

Let's introduce ourselves. I've written a function that outputs my name, and your task is to write a function that outputs your name.

1234567
# Define the function `say_my_name` def say_my_name(): # The function prints the string `My name is Heisenberg` print('My name is Heisenberg') # Call the function `say_my_name` say_my_name()
copy

The say_my_name function simply prints the phrase 'My name is Heisenberg' to the screen, and we can call this function to see this output.

Oppgave

Swipe to start coding

Write a function that prints your name in the console.

  1. Define a function named print_name.
  2. Inside the function, use print() to output a string with your name in the format: My name is {your name}, where {your name} is replaced with your actual name.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 2
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt