Python Basics for Absolute Beginners

A simple introduction to Python programming for those who have never coded before.

Welcome to your first Python tutorial! Python is a popular programming language known for its simplicity and readability, making it perfect for beginners. In this tutorial, you will learn the most basic concepts to get started with Python programming.

Let's begin by understanding how to display text using Python. The most common way to show output is by using the print() function. This function prints whatever you pass inside the parentheses to the screen.

python
print("Hello, world!")

If you run the above code, you should see the message Hello, world! on the screen. This is your first Python program! Now, if you get an error like SyntaxError: EOL while scanning string literal, it means you forgot to close a quote. Always make sure your strings are enclosed in matching quotes, either single ('') or double ("").

Next, let's look at variables. Variables are used to store data so you can use it later. You can create a variable by giving it a name and assigning a value with the = sign.

python
name = "Alice"
age = 25
print(name)
print(age)

In this example, we created two variables: name and age. We assigned a string to name and a number to age. When printing these variables, their stored values show up. If you get a NameError like NameError: name 'nme' is not defined, it usually means you misspelled your variable. Double-check your variable names to fix this.

Finally, let's see how to ask the user for input. Use the input() function, which shows a prompt and waits for the user to type something.

python
user_name = input("What is your name? ")
print("Hello, " + user_name + "!")

When you run this code, Python waits for you to type your name. Then it prints a personalized greeting. If you forget the closing parenthesis in input function like input("What is your name?" you will get a SyntaxError. Always check your parentheses and quotes carefully to avoid such errors.

To sum up, today you learned how to display output with print(), store data in variables, and get input from the user. These are the building blocks for writing any Python program. Practice these basics and soon you will be ready to explore more exciting Python features!