Introduction to DataTypes
- What are data types?
- Importance of data types in programming
- Python is dynamically typed
- Data types determine the kind of operations possible
3.
Numeric Data Types
- int – Integer numbers (e.g., 5, -10)
- float – Floating point numbers (e.g., 3.14, -0.001)
- complex – Complex numbers (e.g., 3+5j)
Example:
a = 10
b = 3.5
c = 2 + 3j
4.
String Data Type
- Text data enclosed in quotes
- Immutable sequences of characters
- String operations: slicing, concatenation, repetition
Example:
name = "Python"
print(name[0]) # Output: P
5.
Boolean Data Type
- bool: True or False
- Used in conditional statements
- Often results from comparison operators
Example:
is_valid = True
print(5 > 3) # Output: True
6.
List Data Type
- Ordered, mutable collection
- Can contain elements of different types
- Supports indexing, slicing, appending, etc.
Example:
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
7.
Tuple Data Type
- Ordered, immutable collection
- Elements can't be changed
- Uses parentheses ()
Example:
coordinates = (10, 20)
8.
Set Data Type
- Unordered, unique elements
- Mutable but no duplicate values
- Useful for membership tests and set operations
Example:
colors = {"red", "blue", "green"}
9.
Dictionary Data Type
- Unordered collection of key-value pairs
- Keys must be unique and immutable
- Uses curly braces {}
Example:
person = {"name": "Alice", "age": 25}
10.
Summary
- Pythonhas rich and flexible data types
- Common types: int, float, str, bool, list, tuple, set,
dict
- Choosing the right data type is key to efficient
programming