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

bookWriting Your First Python Code

Svep för att visa menyn

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 2

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Avsnitt 1. Kapitel 2
some-alt