Welcome to the first day of your 100-day journey to mastering Python! Today, we’ll start with the absolute basics, laying a solid foundation for the exciting concepts to come. Our goal for today is to write your very first lines of Python code and understand the fundamental building blocks of the language.
What is Python?
Python is a high-level, interpreted programming language known for its readability and simplicity. It’s incredibly versatile and is used in a wide range of applications, including web development, data science, artificial intelligence, and automation. Its clean syntax makes it an excellent choice for beginners.
Setting Up Your Environment
To start programming in Python, you need a place to write and run your code. While you can install Python directly on your computer, the easiest way to begin is by using an online Integrated Development Environment (IDE). These platforms allow you to write and run code directly in your web browser without any complex setup. A popular choice for beginners is Replit. Simply create a free account and start a new Python project.
Your First Python Program: “Hello, World!”
It’s a time-honored tradition in programming to make your first program print the phrase “Hello, World!”. In Python, this is incredibly straightforward. In your code editor, type the following line:
Python
print("Hello, World!")
Now, run the code. You should see "Hello, World!" displayed in the output console. Congratulations, you've just written your first Python program! The print() function is used to display output to the screen.
Understanding Comments
Comments are notes in your code that are ignored by the Python interpreter. They are for you and other programmers to understand what your code does. In Python, a comment is created by placing a hash symbol (#) before the text.
Python
# This is a comment. It won't be executed.
print("This line will be executed.")
Good commenting is a crucial habit to develop as you learn to code.
Variables: Storing Information
In programming, we often need to store values. We do this using variables. A variable is like a container with a label that holds some data. In Python, you can create a variable and assign it a value like this:
Python
message = "Welcome to Day 1 of your Python journey!"
print(message)
In this example, message is the variable, and it stores the string "Welcome to Day 1 of your Python journey!". When we print the message variable, it displays the value it holds.
Variables can also store numbers:
Python
day = 1
print("You are on day:")
print(day)
A Quick Introduction to Data Types
In the examples above, you’ve already encountered two of Python’s basic data types:
- Strings: A sequence of characters, enclosed in single (
') or double (") quotes. “Hello, World!” is a string. - Integers: Whole numbers, like
1,100, or-5.
We will explore more data types in the coming days.
Today’s Exercise
To practice what you’ve learned, try the following:
- Create a new Python file.
- Add a comment at the top with your name and the date.
- Create a variable to store your favorite movie and another to store the year it was released.
- Use the
print()function to display a sentence about your favorite movie and its release year, using the variables you created.
That’s it for Day 1! You’ve taken your first significant step into the world of Python. Tomorrow, we’ll dive deeper into strings and learn how to manipulate them. Keep practicing!