Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Writing Your First Python Code | Getting Started with Python
Introduction to Python

bookWriting Your First Python Code

Sveip for å vise menyen

1
print('Hello, World!')
copy

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:

  1. print

    • This is a built-in Python function. It tells Python to display something on the screen.
  2. Parentheses ()

    • Functions in Python use parentheses to enclose their arguments. Here, the parentheses surround the message you want to display.
  3. Quotation marks ' '

    • In Python, anything inside single (' ') or double (" ") quotes is considered a string—a sequence of characters (text).
  4. '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.

question mark

Which of the following is the correct way to print 'Hello, World!' in Python?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 2

Spør AI

expand

Spør AI

ChatGPT

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
some-alt