Free sample lesson ยท Python Basics for Data Analysis

First Code

How do computers turn simple text into powerful commands?

Lesson 1 of the Wondering course Python Basics for Data Analysis

Talking to a Computer

A computer does not guess what you want. It follows instructions, one line at a time.

Python is a language for writing those instructions. The text you type is called code.

Your job as a beginner is simple: write a command, run it, and look at what comes back.

That small cycle is the foundation of everything else in programming.

The beginner coding cycle
  • Write a command: You type an instruction in Python syntax.
  • Execute it: The Python interpreter runs your line of code.
  • Observe the result: You read what appears in the console.

Meet the Print Function

The print function is the most basic tool for sending information out of your program.

It tells Python to display something so you can read it.

Without print, your code can calculate quietly and show you nothing at all.

A single line of Python code sending its result to the console

Notice how the typed command sits above and the displayed result appears below, in the console area.

This is why print is almost always the first command a beginner learns.

How Print Is Written

A command in Python has a shape, and that shape is called syntax.

For print, you write the word print, then a pair of parentheses, then the thing you want shown inside them.

Text goes inside quotation marks. Numbers do not need them.

Get the shape right and Python obeys. Get it wrong and Python stops and complains.

Building one print command
  • The name: Write the word print to call the function.
  • The parentheses: Add a pair of parentheses right after the name.
  • The content: Put inside what you want displayed, with quotation marks around text.
  • Run it: Execute the line and read the result in the console.

Readable and Powerful

Python is often described as readable. The word print means roughly what it looks like it means.

That readability is not decoration. It lets you check your own instructions before the computer runs them.

Readability and power sit together in the same language.

Simple text on the screen becomes an action the interpreter carries out.

Two qualities of Python syntax
  • Readable
  • Powerful

Sequential Instructions

Python reads your script from top to bottom.

If you write three print commands, they run in that exact order and display in that exact order.

This is the core logic that never changes, no matter how large your programs become.

Complex algorithms are still just clear, sequential instructions the interpreter can translate into action.

Can order alone build complexity?

Where This Leads

Your first print statement is small, but it opens a path.

From here you move to handling data structures, then to statistical calculations.

Later, those same sequential instructions become automated models that forecast trends from historical data.

Each stage rests on the one below it.

From first script to prediction
  • Predictive models: Automated models that forecast trends from historical data inputs.
  • Statistical calculations: Performing calculations on the data you hold.
  • Data structures: Handling organised collections of data.
  • First code: Writing a command, executing it, and observing the result.

Each level rests on the one below

Your Key Takeaways

Programming is giving clear, sequential instructions to an interpreter.

The print function is your first and simplest way to see what your code is doing.

Master the workflow of writing, executing, and observing, and the rest is built on top of it.

You now have the foundation.

Quick review

Check yourself

What is the main purpose of the print function in Python?

  • Display information
  • Store information permanently

Answer: Display information

The print function displays information so the programmer or user can read it. Without it, a program may calculate without showing a result.

In Python, _____ contains instructions, _____ describes their required shape, and the _____ carries them out.

Answer: In Python, code contains instructions, syntax describes their required shape, and the interpreter carries them out.

Code is the text of the instructions. Syntax is the form those instructions must follow. The interpreter translates the instructions into actions.

Which Python statement correctly displays the word Hello?

  • print("Hello")
  • print(Hello)
  • print "Hello"
  • display("Hello")

Answer: print("Hello")

Text must be placed inside quotation marks, and print must be followed by parentheses. The other choices either omit quotation marks or use the wrong command shape.

Keep going

This is lesson 1 of 9 in Python Basics for Data Analysis. Next up:

  1. Variables
  2. Data Types
  3. Lists
  4. Dictionaries
  5. Loading Data

Start this course free

Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.