You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
index_of_four = my_list.index(4) # index_of_four is 3
@@ -249,58 +265,54 @@ sample_set = {1, 2, 3}
249
265
sample_set2 =set([1, 2, 3])
250
266
```
251
267
268
+
269
+
270
+
### Dictionaries
271
+
Dictionaries are a fundamental data structure in Python that allows for the storage of key-value pairs. They are mutable, unordered collections, and each key must be unique.
dict_length =len(sample_dict) # returns the number of key-value pairs in the dictionary (2 in this case)
284
313
```
285
314
286
315
287
-
### Dictionaries
288
-
Dictionaries are a fundamental data structure in Python that allows for the storage of key-value pairs. They are mutable, unordered collections, and each key must be unique.
Strings are a fundamental data type in Python that represent sequences of characters. They are immutable, meaning their elements cannot be changed after creation.
353
367
368
+
```python
369
+
# Ways to Initialize a string
370
+
my_string ="Hello, World!"
371
+
my_string =str(123) # Convert an integer to a string
372
+
# loop through string
373
+
for char in my_string:
374
+
print(char)
375
+
# character ascii
376
+
ascii_value =ord('a') # ascii_value is 97
377
+
char =chr(97) # char is 'a'
378
+
379
+
# format string
380
+
name ="Alice"
381
+
age =30
382
+
formatted_string =f"My name is {name} and I am {age} years old."# Using f-strings
383
+
formatted_string ="My name is {} and I am {} years old.".format(name, age) # Using format method
384
+
385
+
escaped_string ="He said, \"Hello, World!\""# Use backslash to escape quotes
386
+
387
+
# String Methods like upp
388
+
upper_case = my_string.upper() # upper_case is "HELLO, WORLD!"
389
+
lower_case = my_string.lower() # lower_case is "hello, world!"
0 commit comments