Python for Beginners
What is Python?
Python is a high-level programming language that’s used by hobbyists and Google engineers alike. Almost any technical field you can think of: Science, Engineering, Finance, Web, Robotics, Home Automation, Artificial Intelligence (AI) – all make heavy use of Python.
Table of Contents
Key Features of Python
- Easy to Learn: Python has a simple syntax that resembles English, making it accessible for beginners.
- Interpreted Language: Python doesn’t need to be compiled; the Python interpreter runs the code directly.
- Multi-paradigm: Python supports procedural, object-oriented, and functional programming.
- Large Standard Library: Python comes with a large set of built-in modules and packages, providing tools for everything from math operations to file handling and web interactions.
- Third-party Libraries: A vast selection of external modules and packages give inventors access to specialised tools for AI, Computer Vision, and almost anything you can think of. Examples include Flask, OpenCV, MQTT, Scikit-learn, Pillow, PySerial, etc.
Why Learn Python?
Python is a great first language for new programmers due to its clarity and ease of use. It’s used by major companies like Google, Netflix, Instagram, and NASA for various tasks. Whether you’re interested in web development, automation, data analysis, or even game development, Python has the tools to help you achieve your goals.
Some of the major benefits of learning Python include:
- Versatility: Python is used across a wide range of industries.
- Community Support: Python has a huge community of developers, meaning there are countless resources, tutorials, and libraries to help you.
- Job Opportunities: Python is in high demand across industries such as finance, tech, education, and more.
Setting Up Python
Before you can start coding, you’ll need to install Python on your computer.
Installing Python

1. Download Python:
- Go to the official Python website.
- Download the latest version of Python for your operating system (Windows, macOS, or Linux).
2. Install Python:
- Follow the installation instructions. Be sure to check the box that says “Add Python to PATH” during installation, as it makes running Python from the command line easier.
3. Verify Installation:
- Open your terminal or command prompt, and type:
bash python --version - You should see the version of Python that you installed. If it shows up correctly, Python is successfully installed!
Choosing an Editor or IDE
An Integrated Development Environment (IDE) or a simple text editor is used to write and run Python code. Here are some popular options:
- IDLE: Comes installed with Python and is good for beginners.
- VS Code: A popular and lightweight code editor with full Python support.
- PyCharm: A powerful Python IDE with many features for advanced development.
You can start with a plain text editor, IDLE or VS Code, which are easier for beginners, and then move on to more complex IDEs as you get comfortable.

Python in Visual Studio Code
Writing Your First Python Program
Let’s get right into it by writing our first Python program!
The Famous “Hello, World” Example
It’s traditional to begin by printing “Hello, World!” to the screen. Here’s how you do it in Python.
- Open your Python editor (IDLE, VS Code, or whatever).
- In a new file, type the following code:
print("Hello, World!")
- Save the file with a
.pyextension, for example,hello_world.py. - Run the program by opening a terminal or command prompt, navigating to the file’s location, and typing:
python hello_world.py
Explanation of the Code:
print(): This is a built-in Python function that outputs data to the screen."Hello, World!": This is a string of text that you want to display.
When you run this program, Python will display the text Hello, World! on the screen.
Running Python Programs
There are a few different ways to run Python code:
1. Using the Python Interactive Shell:
- Open your terminal or command prompt.
- Type
pythonand hit Enter to enter the Python interactive shell. - You can type Python commands directly here. For example:
print("Hello, Python!")
2. Running Python Scripts:
- Save your Python code in a
.pyfile. - Open a terminal, navigate to the file’s location, and run it with:
python filename.py
3. Using an IDE:
- Open your Python script in your chosen editor (like VS Code or PyCharm).
- Most IDEs allow you to run the code directly within the editor by pressing a “Run” button or using a shortcut (such as F5 in IDLE).
Key Concepts Recap
- Python is a versatile, easy-to-learn programming language.
- You can install Python from python.org.
- You wrote your first Python program,
Hello, World!, and ran it using the terminal or an IDE. - The
print()function is a simple way to display output in Python.
Exercises
- Write a Python program that prints your name to the screen.
- Experiment by printing different messages using the
print()function. Try adding multipleprint()statements in your script.
Next time, we’ll dive into variables and explore how you can store and manipulate data in your Python programs.
FAQ
Q1: Why do I need to check the “Add Python to PATH” box during installation?
A1: Checking the “Add Python to PATH” box during installation ensures that your system can recognize and run Python from any directory via the command line. Without this, you would have to manually navigate to Python’s installation folder or modify system settings to make the python command work globally.
Q2: What should I do if typing python --version doesn’t work?
A2: If the python --version command doesn’t work, it’s possible that Python wasn’t added to your system’s PATH during installation. You can fix this by:
- Re-running the Python installer and ensuring you check the “Add Python to PATH” option.
- Manually adding Python to your system’s PATH environment variable.
On Windows, you can also try usingpython3instead ofpython.
Q3: I installed Python, but what’s the difference between python and python3 in the terminal?
A3: Some systems, especially Linux and macOS, may have both Python 2 and Python 3 installed. On these systems, python may refer to Python 2.x, and python3 refers to Python 3.x. If you specifically want to use Python 3 (which is recommended), use python3 in the terminal. On some systems, python already points to Python 3, but it’s good to be aware of this difference.
Q4: What’s the difference between a terminal, a command prompt, and a Python shell?
A4:
- Terminal/Command Prompt: This is the general interface where you can run various system commands, including running Python programs. On Windows, it’s called Command Prompt (or PowerShell); on macOS/Linux, it’s the Terminal.
- Python Shell: This is an interactive environment within the terminal where you can run Python commands line by line. You access it by typing
python(orpython3on some systems) in the terminal.
Q5: Can I run Python programs without using a terminal or command prompt?
A5: Yes, you can run Python programs using an IDE like VS Code, PyCharm, or even IDLE (which comes with Python). These tools allow you to write and execute Python code without needing to use the terminal. However, it’s useful to know how to run Python from the terminal, especially for working on larger projects or debugging.
Q6: What if I don’t like any of the IDEs mentioned? Are there other options?
A6: Yes, there are many other IDEs and text editors you can use for Python programming, depending on your preferences. Some other popular options include:
- Sublime Text: A lightweight and customizable text editor.
- Atom: An open-source editor developed by GitHub.
- Jupyter Notebook: Commonly used in data science and education for running Python code interactively in a browser interface.
You can switch between editors until you find one that fits your workflow best.
Q7: My Python script runs, but the window closes immediately after. What can I do?
A7: This often happens when you run a Python script by double-clicking on the .py file directly, especially on Windows. The program runs in a terminal, but the terminal closes as soon as the script finishes. To prevent this, you can:
- Open the terminal manually, navigate to the file’s directory, and run the script using
python script_name.py. - Add a line like
input("Press Enter to exit...")at the end of your script to pause the program before it closes.
Q8: Can I run Python on my phone or tablet?
A8: Yes, you can run Python on mobile devices. There are several apps available that allow you to write and run Python code:
- Pydroid 3: A Python IDE for Android.
- Pythonista: A Python IDE for iOS.
These apps are great for quick coding sessions, but for more complex projects, a desktop environment is recommended.
Q9: Do I need to install anything else besides Python to get started?
A9: For basic Python programming, installing Python itself is sufficient. Python comes with a large standard library that has many useful modules, so you can do a lot without needing additional software. As you get into more advanced topics (like web development or data science), you may need to install additional libraries or packages using pip, Python’s package manager.
Q10: Why does Python use indentation instead of braces like other languages?
A10: Python uses indentation to define blocks of code (such as loops and conditionals) instead of braces {}. This enforces clean, readable code, as proper indentation is mandatory. While this may feel unfamiliar if you’ve worked with languages like C, C++, or Java, it leads to more consistent and readable code once you get used to it.
Q11: How can I practice what I’ve learned?
A11: Besides trying out the provided exercises, here are a few additional ideas to reinforce your learning:
- Write a program that prints different greetings depending on the time of day (e.g., “Good Morning” in the morning, “Good Evening” at night).
- Experiment with the
input()function to create a program that asks the user for their name and greets them. - Practice using
print()with different data types, such as numbers and variables.
Q12: What if I make a mistake in my code?
A12: Mistakes in your code, or syntax errors, are normal when learning to code. Python will give you an error message that helps explain what went wrong. Read the error message carefully, as it often points to the exact line in your code where the issue is. In some cases, it may be something as simple as a missing parenthesis or a typo. Debugging is a key part of programming, so don’t worry about errors — they’re a learning opportunity!
Q13: I’ve heard Python 2 is different from Python 3. Should I learn Python 2?
A13: No, Python 2 reached its end-of-life on January 1, 2020, and is no longer supported. Python 3 is the current and actively maintained version of Python. If you’re just starting to learn, you should focus on Python 3. Most libraries and frameworks have also moved to Python 3, so it’s the future of the language.
Q14: Can I run Python in the browser?
A14: Yes, there are online platforms where you can write and run Python code directly in your web browser, without needing to install anything on your computer. Some popular ones include:
- Repl.it
- Google Colab
- Jupyter Notebooks (via cloud services)
These platforms are especially useful if you’re on a device where you can’t install software or if you want to quickly test out code snippets.
Q15: How long will it take to learn Python?
A15: The time it takes to learn Python depends on your goals and prior programming experience. If you’re a total beginner, it could take a few weeks to a few months to become comfortable with basic concepts. The key is consistent practice. Start with small, manageable projects, and gradually increase the complexity as you learn more.
