Variables and Data Types of Python by Copilot Github | Ballu Python 835430
In Python, variables are used to store data, and data types define the type of data a variable can hold. Here are some common data types in Python:
1. **Integer**: Whole numbers, e.g., `1`, `42`, `-5`
2. **Float**: Decimal numbers, e.g., `3.14`, `0.001`, `-2.5`
3. **String**: Sequence of characters, e.g., `"hello"`, `'world'`
4. **Boolean**: Represents `True` or `False`
5. **List**: Ordered collection of items, e.g., `[1, 2, 3]`, `['a', 'b', 'c']`
6. **Tuple**: Ordered, immutable collection of items, e.g., `(1, 2, 3)`, `('a', 'b', 'c')`
7. **Dictionary**: Collection of key-value pairs, e.g., `{'name': 'Alice', 'age': 25}`
8. **Set**: Unordered collection of unique items, e.g., `{1, 2, 3}`, `{'a', 'b', 'c'}`
Here's an example demonstrating these data types:
```python
# Integer
age = 25
# Float
pi = 3.14159
# String
name = "Alice"
# Boolean
is_student = True
# List
fruits = ["apple", "banana", "cherry"]
# Tuple
coordinates = (10.0, 20.0)
# Dictionary
person = {
"name": "Alice",
"age": 25,
"is_student": True
}
# Set
unique_numbers = {1, 2, 3, 4, 5}
```
You can use these variables and data types to store and manipulate data in your Python programs.
Comments
Post a Comment