Writing Your First Python Code
Sveip for å vise menyen
1print('Hello, World!')
Step-by-Step Breakdown: Printing 'Hello, World!'
Let's look at the code sample:
print('Hello, World!')
Here's what each part of this line does:
-
print- This is a built-in Python function. It tells Python to display something on the screen.
-
Parentheses
()- Functions in Python use parentheses to enclose their arguments. Here, the parentheses surround the message you want to display.
-
Quotation marks
' '- In Python, anything inside single (
' ') or double (" ") quotes is considered a string—a sequence of characters (text).
- In Python, anything inside single (
-
'Hello, World!'- This is the string you want to display. You can replace it with any text you like.
When you run this code, Python will output:
Hello, World!
This is often the very first program written when learning a new programming language. It demonstrates how to use the print function to show information on the screen.
Now it's your turn! Try writing your own greeting message in Python. For example, you could print your name or a fun message. Type your code below using the print() function.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 2
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Seksjon 1. Kapittel 2