-
Integer (int):
- Represents whole numbers (positive, negative, or zero).
- Example:
age = 25 print("My age is", age)
-
Float (float):
- Represents decimal numbers.
- Example:
pi = 3.14 print("The value of pi is approximately", pi)
-
String (str):
- Represents a sequence of characters (text).
- Example:
name = "Alice" print("Hello,", name)
-
Boolean (bool):
- Represents truth values (
True
orFalse
). - Example:
is_raining = True print("Is it raining?", is_raining)
- Represents truth values (
-
List:
- Represents an ordered collection of items (mutable).
- Example:
fruits = ["apple", "banana", "cherry"] print("My favorite fruits:", fruits)
-
Tuple:
- Similar to a list but immutable (cannot be modified after creation).
- Example:
coordinates = (10, 20) print("Coordinates:", coordinates)
-
Dictionary (dict):
- Represents key-value pairs (associative array).
- Example:
person = {"name": "Bob", "age": 30, "city": "New York"} print("Person details:", person)
-
Set:
- Represents an unordered collection of unique elements.
- Example:
colors = {"red", "green", "blue"} print("Available colors:", colors)
-
NoneType (None):
- Represents the absence of a value.
- Example:
result = None print("Result:", result)
These examples demonstrate the basic data types in Python. Feel free to experiment with them and build more complex programs! 🐍✨