Your First Steps with Python: Writing Your First Code Lines

Python Python Basics

Python is a multifaceted and powerful programming language that’s known for its simplicity and readability. If you’re new to programming or just starting out with Python, this article will guide you through writing your very first code lines.

Table of Contents

Setting Up Your Environment

Before we dive into coding, let’s make sure you have the necessary tools installed. You’ll need Python itself and a text editor or an Integrated Development Environment (IDE) to write and run your code.

Installing Python

If you haven’t already, download and install the current version of Python from the official website: https://www.python.org/downloads/. Follow the installation instructions for your operating system.

Choosing a Text Editor or IDE

There are several text editors and IDEs that work well with Python. Some popular options include Visual Studio Code, PyCharm, and Jupyter Notebook. Choose one that suits your needs and install it.

Writing Your First Python Code

The most traditional first program in any programming language is the "Hello World" program. Open your text editor or IDE and type the following lines:


print("Hello World from Python Script")

Save the file with a .py extension, for example, my_hello_world.py. To run the code, open a terminal or command prompt in the same directory as your Python file and type:


python my_hello_world.py

You should see the message "Hello World from Python Script" printed out in the terminal. Congratulations! You’ve written and run your first Python program.

Variables

Variables are used to store data in a programming language. In Python, you can assign a value to a variable with an equals sign:


custom_variable = "Hello World from Python Script"
print(custom_variable)

Save the file and run it to see the output. You can change the value of a variable at any time by reassigning it:


custom_variable = "Hello, Python!"
print(custom_variable)

Comments

Comments are used to add explanations or notes to your code. In Python, comments start with the hash symbol # and continue until the end of the line:


# This is a comment
print("Hello World")

Next Steps

Now that you’ve written your first lines of Python code, it’s time to explore more. In the next articles, we’ll cover topics like data types, control structures, functions, and more. Stay tuned!

To top