Codes and contents for the Day 1 class
Variables and Data Types
This section covers the basics of variables and data types in Python. Some of the data types are:
Integer, Float, String, Boolean, List, Tuple, Dictionary
Integer is a whole number, like 4, 5, 6.
Float is a decimal number, like 4.5, 5.6, 6.7.
String is a sequence of characters, like "Hello", "World".
Boolean is a value that can be either True or False.
List is a collection of items, like [1, 2, 3], ["apple", "banana", "cherry"].
Tuple is a collection of items, like (1, 2, 3), ("apple", "banana", "cherry").
Dictionary is a collection of key-value pairs, like {"name": "Asib", "age": 21}.
| variables_and_data_types.py | |
|---|---|
- Integer variable
- Integer variable with type annotation
- String variable
- Integer variable
- Float variable
- Boolean variable
String Formatting and Printing
- String formatting with f-string
- String formatting with format method
- String concatenation with comma without type casting
- String concatenation with + operator with type casting
Type Casting or Converting Data Types
- Type casting from string to integer
List Operations
List Creation
| list_creation.py | |
|---|---|
List Accessing from index
- 'Asib'
- 'Khalid'
List Slicing
| list_slicing.py | |
|---|---|
- ['Asib', 21]
- ['Khalid', 25]
- ['Bappy', 22]
List Modification
- Modifying the value of index 1
- Modifying the value of index 3
List Copying
The script demonstrates two methods for copying lists:
- Using list() function: data2 = list(data)
- Using slicing: data3 = data[:]
- Copying the list using list() function
- Copying the list using slicing