We're making some improvements. Some features may be temporarily unavailable.
beginner20 min

Variables & Data Types

Numbers, strings, booleans, and how to store data

What are Variables?

A variable is like a labeled box that stores a value. You create a variable by assigning a value to a name using =.

Creating Variables

Output
Run your code to see output here

Variable Naming Rules

  • Must start with a letter or underscore _
  • Can contain letters, numbers, and underscores
  • Case-sensitivename and Name are different
  • Use descriptive names: student_count not sc

Python Data Types

Python has several built-in data types:

Numbers

Working with Numbers

Output
Run your code to see output here

Strings

Strings are sequences of characters, enclosed in "..." or '...':

String Operations

Output
Run your code to see output here

Booleans

Booleans are either True or False:

Boolean Values

Output
Run your code to see output here

Type Conversion

You can convert between types:

Type Conversion

Output
Run your code to see output here

Check Your Understanding

What is the value of `name` after: `name = 'Ali'; name = 'Sara'`?

Check Your Understanding

What does `type(3.14)` return?

Exercise

Create a variable called `first_name` with your name, a variable called `birth_year` with your birth year, and print a sentence like 'My name is X and I was born in Y'.

Python will load on first run

Questions & Discussion

Sign in to ask a question or join the discussion.

Loading comments...