1. Variable
- Explanation: A variable is a name that refers to a value stored in memory. In Python, variables are dynamically typed, meaning you don't need to declare the type of a variable before assigning a value to it.
Example:
x = 10 # Here, x is a variable storing the value 10.
2. Data Types
- Explanation: Data types define the type of value a variable can hold. Common data types in Python include integers ('
int'
), floating-point numbers ('float'
), strings ('str'
), and booleans (bool
).
Example:
age = 25 # int height = 5.9 # float name = "Alice" # str is_student = True # bool
3. List
- Explanation: A list is a collection of items that are ordered and changeable. Lists are one of the most versatile data structures in Python.
fruits = ["apple", "banana", "cherry"] # A list of fruits.
4. Tuple
- Explanation: A tuple is similar to a list, but it is immutable, meaning that once it is created, its elements cannot be changed.
coordinates = (10, 20) # A tuple representing coordinates.
5. Dictionary
- Explanation: A dictionary is a collection of key-value pairs. Each key is unique, and it is used to access the corresponding value.
5. Dictionary Explanation: A dictionary is a collection of key-value pairs. Each key is unique, and it is used to access the corresponding value. Example:
No comments:
Post a Comment