Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 149 ยท Getting Started

Getting Started with Python

Meet Python, one of the most popular programming languages. Print your first messages, store values in variables, read input and do quick calculations, all in your browser.

Python is a programming language known for code that reads almost like plain English. It powers websites, data analysis, scientific research, automation scripts and machine learning, and it's often the first language people learn.

This lesson has live editors. Press Run (or Ctrl + Enter) and the code executes right here in your browser. The first run takes a few seconds while Python itself loads; after that it's quick.

Your first program

A program is a list of instructions the computer carries out from top to bottom. The classic first instruction is to show a message with print():

Python Hello, Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

  • print is a function: a named action you can use.
  • The parentheses () hold what you give to the function.
  • Text goes inside quotes. In Python, text values are called strings.

Change the messages and run the code again. Then try removing one of the quotes and see what happens: Python stops and explains what went wrong. Reading these error messages is a skill every programmer practices daily.

Python as a calculator

Python understands arithmetic, so you can use it as a very capable calculator:

Python Arithmetic

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Anything after a # is a comment. Python ignores it, so comments are a place for notes to human readers.

Variables

A variable is a name that refers to a value. You create one with a single equals sign, which means "store this", not "is equal to":

Python Variables

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Good variable names say what the value means: temperature is far clearer than t. Python's convention is lowercase words joined by underscores, as in rain_expected.

Tip: print() accepts several values separated by commas and puts a space between them, which is handy for mixing text and numbers.

Reading input

Programs become interactive when they ask the user for information. The input() function reads one line of text. In this editor, type your answers in the Input box under the code. Each line answers one input() call:

Python Asking questions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first line borrows date from Python's built-in datetime module so the program knows today's date; you'll learn about modules later. input() always gives back a string, even when the user types digits. int(year) converts that text into a whole number so we can do arithmetic with it. Try typing something that isn't a number as the year and look at the error you get.

f-strings: tidy messages

Joining text and values with commas works, but Python offers a neater way called f-strings. Put an f before the quotes and write any variable or expression inside curly braces:

Python f-strings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The :.2f part formats the number with exactly two decimal places.

Where Python is used

Python is a general-purpose language, so you will meet it in many fields:

  • Web back ends with frameworks such as Django, Flask and FastAPI.
  • Data science, analysis and machine learning with NumPy, pandas, scikit-learn and PyTorch.
  • Automation and scripting: renaming files, reading spreadsheets, calling web APIs, driving other programs.
  • Scientific computing, finance, education and research.
  • DevOps and cloud tooling, testing, and glue code that connects systems written in other languages.
  • Games, desktop tools and hardware projects (see Pygame, tkinter and Python for IoT).

Large companies have said publicly that Python is part of their stack: YouTube and Instagram (web back ends, with Django at Instagram), Spotify and Netflix (data analysis, recommendations and internal automation), Dropbox (clients and servers), Uber (data and machine learning) and Pinterest (back-end services). The exact role differs from company to company, and usually Python sits beside other languages instead of replacing them.

Strengths and weaknesses

Strengths Weaknesses
Clear, readable syntax that is quick to learn Slower than compiled languages such as C++ or Rust for raw number crunching
A huge standard library and ecosystem on PyPI The Global Interpreter Lock limits CPU-bound threads (free-threaded builds are changing this, see What's new in Python 3.13)
Runs on Windows, macOS and Linux, and has a big community Weaker fit for mobile apps and low-level system code
Dynamic typing speeds up writing and experimenting Type mistakes show up at run time, unless you add type hints and a checker
Excellent for gluing C/C++/Rust libraries together Higher memory use than leaner languages

The slow parts are usually small. Python code tends to orchestrate fast libraries written in C, so the trade is often worth it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does print("2 + 3") show?

    The quotes make it a string, so Python prints the text exactly as written. print(2 + 3) would show 5.
  2. 2. What does 17 // 5 evaluate to?

    // is whole-number (floor) division. 17 % 5 gives the remainder, 2.
  3. 3. What type of value does input() return when the user types 42?

    input() always returns a string. Convert it with int() or float() before doing arithmetic.
  4. 4. Which line correctly prints "Hi, Sam" when name = "Sam"?

    Only an f-string (with the f prefix) replaces with the variable's value.

Summary

  • print() shows values; text values are strings written in quotes.
  • Python can do arithmetic with + - * / // % **.
  • Variables store values under a name using =, and can change later.
  • input() reads a line of text; convert it with int() or float() to calculate with it.
  • f-strings such as f"Hello {name}" mix text and values cleanly.

Next: Running Python Code, where you'll see the different ways to run Python, on your own computer and here in the browser.