Python Tutorial - Part 2: Data Types and Variables
Tuesday, 05 November 2024 - ⧖ 1 minPublished as part of 'python-tutorial' series.
Welcome back to our Python tutorial series! In this second part, we'll explore Python's built-in data types and how to work with variables.
Python Variables
Variables in Python are used to store data values. Unlike many other programming languages, Python has no command for declaring a variable.
name = "Alice"
age = 25
height = 5.6
Basic Data Types
Python has several built-in data types:
Numbers
- int: Integer numbers (e.g., 42, -17)
- float: Decimal numbers (e.g., 3.14, -0.5)
integer_number = 42
floating_number = 3.14159
Strings
Text data is represented as strings in Python.
greeting = "Hello, World!"
multiline_text = """This is a
multiline string"""
Booleans
Boolean values represent True or False.
is_python_fun = True
is_difficult = False
Type Checking
You can check the type of any variable using the type()
function:
print(type(42)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type("Hello")) # <class 'str'>
What's Next?
In Part 3, we'll dive into Python collections: lists, tuples, and dictionaries. These are fundamental data structures you'll use constantly in Python programming.
Please consider giving a ☆ on Marmite Github repository, that helps a lot!