1 Python Basic Data Types

[1]:
12
# The classic first program — printing a string to the console
print("Hello World")
stdout
Hello World
[2]:
123
# Checking the type of a string literal
# Output will show: <class 'str'> — meaning it belongs to the 'str' (string) class
print(type("Hello World"))
stdout
<class 'str'>
[3]:
1234
# Integer (int) — whole numbers, no decimal point
# Use case: counting items, indexing, loop counters
var = 1
print(type(var))  # Output: <class 'int'>
stdout
<class 'int'>
[4]:
1234
# Float — numbers with a decimal point
# Use case: measurements, prices, scientific values, most real-world numbers
var = 1.1
print(type(var))  # Output: <class 'float'>
stdout
<class 'float'>
[5]:
123
# String using double quotes — most common convention
var = "Hello"
print(type(var))  # Output: <class 'str'>
stdout
<class 'str'>
[6]:
1234
# String using single quotes — produces the exact same result
# Both lines above and below create identical string objects in Python
var = 'Hello'
print(type(var))  # Output: <class 'str'>
stdout
<class 'str'>
[7]:
123
# Boolean True — note the capital 'T'
var = True 
print(type(var))  # Output: <class 'bool'>
stdout
<class 'bool'>
[8]:
123
# Boolean False — note the capital 'F'
var = False
print(type(var))  # Output: <class 'bool'>
stdout
<class 'bool'>
[9]:
1234
# None — represents the absence of a value
# Note: None is also case-sensitive; 'none' or 'NONE' would cause a NameError
var = None
print(type(var))  # Output: <class 'NoneType'>
stdout
<class 'NoneType'>