Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Addition | Arithmetic operations
Learn Python from Scratch

book
Addition

Addition in Python is easy - just use "+" sign. You can add numbers or variables (or mix of numbers and variables).

a = 1
b = 2
c = a + b
print(c)
1234
a = 1 b = 2 c = a + b print(c)
copy

Sometimes people use alternative operator: "+=" (it is typically used for brevity). Please see example below (this basically means "increase variable on the left hand side by 1"):

x = 100
x+=1
print(x)
123
x = 100 x+=1 print(x)
copy
Oppgave

Swipe to start coding

Add line to print the sum of 20 and 22.

Løsning

# Add line below to print the sum of 20 and 22
print(20 + 22)



Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 1
# Add line below to print the sum of 20 and 22





Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt