Python Programming with PyCharm
Introduction to Python
What Is Python?
Python is a programming language known for its clear, readable syntax. Think of it less like a cryptic code and more like a set of structured instructions written in something close to English. This design choice was intentional. Its creator, Guido van Rossum, wanted a language that was easy to read and write, even for beginners.
He released the first version in 1991, naming it after the British comedy group Monty Python. Since then, it has grown into one of the world's most popular languages, used for everything from web development and data science to artificial intelligence and simple scripting.
Key features of Python include its simple syntax, a massive standard library (pre-built code for common tasks), and a vibrant community that creates countless third-party tools.
Getting Python on Your Machine
Before you can write Python code, you need to install it. The official source for Python is python.org. You'll want to download the latest stable version available.
The installation process is straightforward on most operating systems:
- Windows: Download the installer from the Python website. During installation, make sure to check the box that says "Add Python to PATH." This lets you run Python easily from the command prompt.
- macOS: Newer versions of macOS may come with Python pre-installed. However, it's often an older version. It's best to download the latest version from python.org and install it.
- Linux: Most Linux distributions come with Python. You can usually install or update it using your distribution's package manager, like
aptfor Debian/Ubuntu oryumfor Fedora.
To check if the installation was successful, open your command prompt (on Windows) or terminal (on macOS/Linux) and type python --version or python3 --version. If it prints a version number, you're all set.
Running Your First Script
There are two primary ways to run Python code: interactively or from a file. The interactive way is great for testing small snippets of code. Just type python or python3 into your terminal and press Enter. You'll see a >>> prompt, which means Python is ready for your commands.
>>> print("Hello, World!")
Hello, World!
For anything more than a line or two, you'll want to save your code in a file. Create a file with a .py extension, like hello.py. Open it in any plain text editor and add your code.
# This is the content of hello.py
print("Hello from a file!")
To run this script, navigate to the directory where you saved the file in your terminal and run the command python hello.py (or python3 hello.py). The output will appear on the next line.
The Building Blocks of Python
Python's syntax has a few key characteristics. The most notable one is its use of indentation. Where other languages use curly braces {} or keywords to define blocks of code (like loops or functions), Python uses whitespace. This forces code to be formatted in a clean, readable way.
Consistent indentation is not just for style in Python, it's a rule. An indentation error is a common bug for beginners.
Another basic element is the comment. Anything on a line after a hash symbol (#) is ignored by Python. Comments are crucial for explaining what your code does, both for others and for your future self.
# Define a variable
name = "Alice"
# A conditional block
if name == "Alice":
# This line is indented, so it's inside the 'if' block.
print("Hello, Alice!")
This simple structure of clean syntax, meaningful indentation, and clear comments is the foundation of writing Python code. You're now ready to start exploring what you can build with it.

