Learning Python for beginners: your first steps from install to first project

TUREFF• •0
Python is a popular first language for good reasons: the code reads almost like English, it runs on every operating system, and the same language is used for automation, data analysis, websites and machine learning. This guide covers the first couple of weeks: getting it running, the handful of ideas that everything else is built on, and where beginners usually get stuck.

Installing Python

  • Windows: download Python from python.org. Python's own Windows downloads page now points to the Python install manager, which installs and updates versions for you. The Microsoft Store also offers it.
  • macOS: install the current release from python.org. Typing python3 in the Terminal on a fresh Mac may offer to install Apple's developer tools instead; the python.org installer is more straightforward for learning.
  • Linux: Python 3 is usually already installed. Type python3 in a terminal to check.
Always install a current Python 3 release. Python 2 reached end of life years ago, and old tutorials written for it will confuse you. For an editor, Visual Studio Code with its Python extension, or Thonny, which is designed for beginners, are both free. You can also start in a browser-based notebook if installing is a hurdle.

Running your first script

Create a file called hello.py, write a single line that calls print with the text "Hello, world" in quotes and brackets, save it, and run it from your editor's run button or by typing python (or python3) followed by the file name in a terminal. Typing python on its own opens the interactive prompt, where each line runs as you press Enter, which is ideal for experiments.

The core ideas

Variables are names for values. You write the name, an equals sign and the value: a name holding the text "Mina", an age holding the number 30. Text goes in quotes; numbers do not. Types matter: "30" in quotes is text, 30 without is a number. The input function always gives you text, so to do maths with what someone typed you convert it with int or float. Lists hold several values in order, written in square brackets and separated by commas. You read items by position, starting from 0, not 1, and add to the end with append. If statements make decisions: if, a condition, a colon, and the indented lines to run. elif and else handle other cases. Loops repeat. A for loop goes through every item in a list or a range of numbers; a while loop repeats as long as a condition is true. Functions package code you want to reuse. You write def, a name, brackets with any inputs, a colon, and an indented body that ends with return and the result. Indentation is not decoration in Python: it is how the language knows which lines belong to an if, a loop or a function. Use four spaces and let your editor do it.

A first project: a to-do list in the terminal

Build a small program that:
  1. Shows a menu: add a task, list tasks, mark one done, quit.
  2. Keeps the tasks in a list.
  3. Loops until the user chooses quit.
  4. Saves the tasks to a text file on exit and loads them on start.
It uses every idea above, plus reading and writing files. Other good first projects are a number-guessing game, a tip calculator, or a script that renames a folder of photos.

Where beginners get stuck

  • Reading errors: the last line of a traceback names the error, and the lines above show where it happened. Read from the bottom up. NameError usually means a typo; IndentationError means mixed or missing indentation; TypeError often means mixing text and numbers.
  • Copying without typing: type examples yourself. Your fingers learn the syntax faster than your eyes.
  • Tutorial hell: watching course after course without building anything. After each new idea, write something small of your own with it.
  • Installing packages: pip installs libraries, but use a virtual environment for each project (the venv module) so they do not clash.
  • Giving up at the first wall: everyone hits one around week two. Searching the exact error message is a real professional skill.
The official Python tutorial on docs.python.org is free and thorough once you have the basics. What was the first program you wrote, or where are you stuck now? Ask in the comments.

Comments (0)