1. What are Variables?
- Explain how variables act as containers for storing data values.
- Show how to declare and use variables in Python with examples:
code:
#any name you can proceed
name = "PythonHub"
age = 23
- Mention Python's dynamic typing (no need to declare variable types explicitly).
2. Python Data Types
->String: Used for text (e.g., "Hello, World!"
).
- Example:
- code:
- greeting = "Hello" print(type(greeting)) # Output: <class 'str'>
->Integer: For whole numbers (e.g.,
42
).- Example:
- number = 100 print(type(number)) # Output: <class 'int'>
->Float: For decimal numbers (e.g.,
3.14
).- Example:
- pi = 3.14 print(type(pi)) # Output: <class 'float'>
->Boolean: For true/false values (
True
, False
).- Example:
- is_active = True
- print(type(is_active)) # Output: <class 'bool'>
3. Type Casting
- Show how to convert between different data types.
- Example:
- age = "16"
- age = int(age)
- print(age) # Output: 16
Comments
Post a Comment