Skip to main content

Command Palette

Search for a command to run...

My first message in Python

Updated
2 min read
My first message in Python

Example 1-1 : Hello world!

'''
Example 1-1 Hello world!
Assign the message "Hello world!" to a variable 
and print it on the screen.
'''

message = "Hello world!" # message is a variable
print(message)

Parts of the Example 1-1:

Comments

Comments are explanations of our code that make it clearer for us and for others, and Python does not read them.

We can see two kinds of comments:

  • Several lines: we write the comment between triple quotation marks: """ comment """ or ''' comment '''
'''
Example 1-1 My first message in Python
Assign the message "Hello world!" to a variable 
and print it on the screen.
'''
  • One line: we write the hash symbol # before the comment.
message = "Hello world!" # message is a variable

Variable

A variable is a label that refers to a certain value. In our example, the variable is messagenad the value is the string "Hello world!".

message = "Hello world!" # message is a variable

Function

A function is a reusable block of code that does something. For example, the print() function displays on the terminal what is inside the parentheses.

print(message)

In our example, the print() function prints the value of the message variable in the terminal:

Hello world!

Exercise 1 - 1

Write the same program, but change the variable value to print a new message. Think about it yourself! You can do it!

You can write your code online here: https://python-online.netlify.app/.

Delete the sample program that appears in the code editor, and write your first program!