1.3 Your First Program: "Hello World!"
Tradition dictates: we write our first program that prints the "Hello World!" message and analyze the basic print() function.
In the programming world, there is an established tradition: the first program every beginner writes is "Hello World!". This simple program has the sole purpose of displaying the "Hello World!" message on the screen. In Python, implementing this tradition is incredibly easy and intuitive.
Try the following code in our live editor:
# This is your first program in Python!
print("Hello, World!")
print('Welcome to LearnPython.ai!')
Code Explanation
- print(): This is a built-in function in Python. Its main purpose is to display messages or values on the screen (in the terminal).
- "Hello, World!": This is a string, which is a sequence of characters. In Python, strings are enclosed in either single (') or double (") quotes.
- # This is...: This line is a comment. Comments are ignored by the Python interpreter and are used to explain the code.
Tip!
When you run the code below in the live editor, you will immediately see the messages appear in the terminal. Congratulations! You have just successfully written and executed your first Python program.
Explore More with AI
Use AI to generate new examples, delve deeper into theory, or get your questions answered.