Ad space (banner)
🐍Python Lessons
Lesson 2 / 69

Variables and print()

This lesson covers the basics of using variables in Python and displaying output with print(), so you can give values names and reuse them. It's written for anyone searching "Python variables tutorial" or "how to use print in Python".

In Python, you store a value by giving it a name — a variable. There's no need to declare a type; you simply write name = "value". Unlike many other languages, there's no let or var keyword required, which is one reason Python is considered one of the easiest languages to start writing. print() displays whatever is inside its parentheses — it's the single most basic command you'll use, including for debugging.

The sample code declares two variables, name and age, then uses print() to display a greeting and the age. print() can take multiple values separated by commas, and it automatically inserts a space between them — a small, convenient touch that's very Python-like.

A common beginner mistake is trying to join a string and a number with +, which raises an error. Writing "Age: " + age triggers a TypeError — you need to either convert the number to a string first, or use print()'s comma syntax instead. Variable names are also case-sensitive, so watch out for typos.

In real-world development, almost everything — user input, data from an API — starts out stored in a variable. How you declare and name variables directly affects how readable and maintainable your code is, which is why it's taken seriously even in professional code review.

Python
OUTPUT

💡 The Python engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)