Python Basics Part 1: Comments, Variables, and Data Types Explained for Beginners

Python Basics – Part 1: Comments, Variables, and Data Types

Over the next few weeks, I’ll be sharing my notes from a 5-week Python training course.
Throughout the course, we covered fundamental programming concepts and practical examples step by step.
From time to time, I’ll also include some of the extra exercise tasks we did during the sessions.

Comments in Python

Single-line comments start with the # symbol and are very common in Python.

# This is a single-line comment
print("Hello, Python!")

You can also write multi-line comments by using triple quotes.
However, technically, these are multi-line strings (often used for documentation, called docstrings), not true comments.

''' 
This is a multi-line comment using single quotes.
It starts and ends with three quotation marks.
'''

"""
You can also use double quotes for multi-line comments.
"""

Variables and Naming Conventions

Variables are containers used to store values.

number1 = 100
print(number1)

Output:

100

Rules for variable names

  • You can use letters, digits, and underscores (_).
  • A variable name cannot start with a digit.
  • Python style convention: lower_snake_case → lowercase letters, words separated by underscores.
  • Other languages often use lowerCamelCase.
my_first_variable = 42
print(my_first_variable)

Output:

42

Tip: Use descriptive variable names — it makes your code much easier to understand.

Data Types in Python

Python has several built-in data types. Let’s look at the basic ones.

Integer

Whole numbers without a decimal point.

number2 = 42
print(number2)
print(type(number2))

Output:

42
<class 'int'>

Float (Floating-Point Number)

Numbers with decimal places — use a dot (.) as the decimal separator.

decimal_number = 123.45
print(decimal_number)
print(type(decimal_number))

Output:

123.45
<class 'float'>

String

A sequence of characters. You can use single or double quotes,
but you cannot mix them within the same string unless you escape one of them.

first_name = 'Peter'
print(first_name)
print(type(first_name))
print("Let's go!")
print('He said: "Get out!"')

Output:

Peter
<class 'str'>
Let's go!
He said: "Get out!"

You can also combine (concatenate) strings:

full_name = first_name + " Parker"
print(full_name)

Output:

Peter Parker

Boolean

Represents truth values: True or False (must be written exactly like this — capital T/F).

bool1 = True
bool2 = False
print(bool1)
print(bool2)
print(type(bool1 and bool2))

Output:

True
False
<class 'bool'>

Booleans are often used in comparisons and conditions:

x = 10
y = 5
print(x > y)   # True
print(x == y)  # False

Output:

True
False
Bonus: Type Overview

You can check the types of multiple values at once:

print(type(number1), type(decimal_number), type(first_name), type(bool1))

Output:

<class 'int'> <class 'float'> <class 'str'> <class 'bool'>

In this lesson, we covered:

  • Comments (#, ''', """)
  • Variables and naming rules
  • Basic data types: int, float, str, bool

Next up: Operators in Python — arithmetic, comparison, and logical operations.