Your First Python
WHAT YOU'LL LEARN
- Understand how Python code you write becomes output on your screen
- Know where to write and run Python code in this course
- Successfully execute your first Python statement
- Recognize the difference between writing code and running it
How This Course Works
Welcome to your first step into programming with Python. Before you write any code, it helps to understand the landscape: where your code lives, how it gets executed, and what you will see when it runs. This course is designed to teach you Python through a combination of explanation, examples you can read, and code you will write and run yourself. Unlike a traditional textbook, this course gives you a place to execute Python right alongside the lessons, so you can experiment and verify what you learn immediately.
Python is a programming language—a formal system for giving instructions to a computer. When you write Python code, you are writing instructions in a format that both humans and computers can understand. Your job as a learner is to learn the rules of this language so you can express your ideas as code. The computer's job is to read your code and do what you ask.
Where Your Code Lives and Runs
In this course, you do not need to install Python on your computer. Instead, this course provides a built-in environment where you can write and run Python code directly in your browser. When you encounter a code example or a practice exercise, you will see an editor where you can type Python statements. That editor is connected to a Python interpreter—a program that reads your code and executes it.
Think of the interpreter as a translator and executor combined. You write code in plain text using Python's vocabulary and rules. The interpreter reads that text, understands what you mean, and performs the actions you have requested. The results—whether they are numbers, text, or error messages—appear in an output area below or beside your code.
Your First Statement
Let us start with the simplest possible Python program. You will use a built-in function called print to display text on your screen. A function is a reusable block of code that performs a specific task. The print function takes whatever you give it and displays it as output.
Hello, World!That single line is a complete Python program. When you run it, the interpreter reads the word print, recognizes it as a function, and executes that function with the text Hello, World! as input. The result is that text appearing on your screen.
Notice the structure: the word print, followed by parentheses, with text inside the parentheses. The text is surrounded by quotation marks. These details matter. Python is precise about syntax—the exact rules for how you write code. If you forget the parentheses or misplace a quotation mark, the interpreter will not understand your instruction and will tell you there is an error.
Understanding What You Just Did
When you ran that print statement, several things happened in sequence. First, you typed the code into the editor. Second, you pressed a button to run it (or the course environment ran it automatically). Third, the Python interpreter read your code and recognized the word print as a function call. Fourth, the interpreter executed that function, passing the text Hello, World! to it. Fifth, the print function displayed that text in the output area. This entire process happens almost instantaneously, but understanding each step helps you grasp what is happening behind the scenes.
The text Hello, World! is called a string in Python. A string is a sequence of characters—letters, numbers, punctuation, spaces—treated as a single piece of text. Strings are one of Python's fundamental data types, meaning they are a category of value that Python knows how to work with. When you put text inside quotation marks, you are telling Python that this is a string, not a command or a variable name.
Printing Numbers and Other Values
The print function is not limited to strings. You can print numbers, the results of calculations, and other kinds of values. Here are some examples:
42
3.14
15In the first line, you print the number 42. Notice there are no quotation marks around it. When you omit quotation marks, Python treats it as a number, not as text. In the second line, you print 3.14, a decimal number. In the third line, you print the result of an expression: 10 + 5. Python evaluates the expression (adds the numbers) and prints the result, 15.
This distinction between text and numbers is crucial. The string "42" and the number 42 are different things to Python. A string is text; a number is a value you can do math with. When you print them, they look similar on the screen, but Python treats them very differently internally.
Common Mistakes When Starting Out
Forgetting the parentheses after print
In modern Python, print is a function and requires parentheses. Without them, Python does not recognize it as a function call and produces an error.
Fix:
print("Hello, World!")Mismatching or missing quotation marks around strings
Every opening quotation mark needs a closing quotation mark. If they do not match, Python cannot tell where the string ends and produces an error.
Fix:
print("Hello, World!")Putting quotation marks around numbers when you want to do math
With quotation marks, 10 + 5 becomes a string of text, not a mathematical expression. Python prints the text literally instead of calculating the sum.
Fix:
print(10 + 5)Using the wrong type of quotation marks
Actually, this is not wrong. Python accepts both single and double quotes for strings. This is a common source of confusion for beginners, but both are valid.
Fix:
Both print("Hello") and print('Hello') work equally well
Writing Multiple Statements
A program can contain more than one statement. Each statement is an instruction for Python to execute. When you write multiple statements, Python executes them one after another, from top to bottom.
My name is Alex.
I am learning Python.
This is my first program.Each line is a separate statement. Python reads the first print statement, executes it, and displays the output. Then it reads the second statement and executes it. Then the third. The output appears in the order you wrote the statements. This sequential execution—doing one thing, then the next, then the next—is a fundamental principle of programming.
The Difference Between Writing and Running
An important distinction: writing code and running code are two separate actions. When you type print("Hello") into the editor, you have written code, but nothing has happened yet. The code sits there, waiting. Only when you run it—by pressing a button or triggering the execution in the course environment—does the interpreter read and execute your instructions.
This separation is important because it means you can write code, review it, edit it, and run it multiple times. You can also write code that has errors. If you run it and the interpreter finds a mistake, it will tell you what went wrong, and you can fix it and run it again. This cycle of writing, running, and fixing is how programmers work every day.
Your Next Steps
Now that you understand how to write and run a simple Python statement, you are ready to explore further. The next lessons will introduce you to variables—named containers for storing values—and more complex operations. But before you move on, take a moment to experiment with the print function. Try printing different strings, numbers, and expressions. Try making mistakes on purpose to see what error messages look like. Familiarity with the editor and the interpreter will serve you well as you progress.
Remember: every program, no matter how complex, is built from simple statements like print. You have just written your first one. That is a real accomplishment. From here, you will learn to combine statements in more powerful ways, but the foundation is the same: write an instruction, run it, see the result.
Key Takeaways
- Python code you write in the course editor is read by a Python interpreter, which executes your instructions and displays output on your screen.
- The print function is a built-in tool for displaying text, numbers, and other values. It requires parentheses and takes the value you want to print as an argument.
- Strings are text values surrounded by quotation marks. Numbers are values without quotation marks. Python treats them differently internally, even if they look similar when printed.
- A program consists of one or more statements executed sequentially from top to bottom. Writing code and running code are separate actions; you can edit and re-run code as many times as you need.
- Syntax—the exact rules for how you write code—matters. Forgetting parentheses, mismatching quotation marks, or other small errors will cause the interpreter to report an error, which you can then fix.