In this article, we'll explore variables and data types in Python.
Variables
A variable is a container for storing data. In Python, you can create a variable and assign a value to it using the assignment operator (=).
Example:
message = "Hello, Python!"
print(message)
In this example, we create a variable named message
and assign it the value "Hello, Python!"
. We then print the value of the variable using the print
function.
Data Types
Python supports various data types, including:
- Integer (int)
- Float (float)
- String (str)
- List (list)
- Tuple (tuple)
- Dictionary (dict)
- Boolean (bool)
Example:
# Integer
age = 25
# Float
height = 5.9
# String
name = "John Doe"
# List
numbers = [1, 2, 3, 4, 5]
# Tuple
coordinates = (10, 20)
# Dictionary
person = {"name": "John", "age": 30}
Each data type has its own characteristics and usage. In the next article, we'll cover basic operations and control structures in Python.