Introduction to Python

Fundamentals: Getting Started with Python

Hello, World!

Below is the code for the “Hello, World!”, your very first line in Python! You can copy it by clicking the “copy” button at the right side of the code block. Then, paste it into your own notebook and run it. However, I recommend you to type it out yourself to get familiar with the syntax and the process of writing code.

To run the code, click anywhere into the cell (the box with the code inside), and then type Shift + Enter (Shift + Return on a Mac) to execute. You can also click the “play” button at the left side of the cell to run it.

print("Hello, world!")
Hello, world!

That text you see below the code block is the output — what the computer “prints” to the screen.

The print() function is how our machine communicates with us. Anything inside the parentheses will be shown to the user.

Let’s create Python code to say hello to you, instead of the world.

# My name is Daniel
print("Hello, Daniel!")
Hello, Daniel!
Exercise

Write the code that displays your favourite food.

print("Pizza")
Pizza

Comments in the Code

You may be wondering what the text is in the cells above that starts with the # hash or pound symbol. This is a comment line. It tells Python that it can ignore anything that follows on that line after the # symbol. Comments are used to help other humans understand what your code does.

Try running the next cell by pressing Shift+Enter. What do you think will happen?

# This is a comment - Python will ignore this line
print("Hello, world!")  # This is also a comment
# And this is another comment
Hello, world!

You can have multiple comment lines in your code, including one after another, and dispersed throughout your code:

# This is an example of code with multiple
# comments, including this one which
# spans multiple lines
print("Hello, BAM!")
# Follow up with an additional print command
print("How is your first day going?")
Hello, BAM!
How is your first day going?

It is good practice to include comments to make your code more understandable for yourself and others.


Debugging

It is normal to make mistakes!

When the code is not properly written, it will raise errors. You should read the error carefully to understand what is causing it.

Debugging is the process of identifying and fixing errors in our code.

Exercise

Fix the following lines of code.

Copy each example into your own notebook first and run it there before opening the solution. You can use the “copy” button at the right side of the code to copy the full block.

print("Hello, world!)
print("Hello, world!"

The first line fails because the closing quote is missing. The second line fails because the closing parenthesis is missing.

print("Hello, world!")
Hello, world!

Need Help?

If you have any questions, feel free to reach out via email at dprecioso@faculty.ie.edu

I’m happy to help!

You can also explore the custom GPT I created for this course:
👉 Python IE Tutor

It’s tailored specifically to support your learning throughout the course.