len()- to calculate the length of the string
ex) len(text)
f[start:stop:step] - to extract the part of the strin to get specific range of the string )
ex)
f[:] - display the entire string
f[:stop] - display chars from the beginning of the string up to (but not including) the chars at the stop index.
f[start:] - display chars from start index to the end of the string
f[start:stop] - display chars from the start index up to (but not including) the character at the stop index.
f[start:stop:step] - display chars from the start index up to (but not including) the char at the stop index, with a step size of step
+) negative slicing starts the end of the string
![]() | ![]() |
|---|
split() - to split a string into a list
ex)
num='403-123-1234'
results = num.split('-')[0]
print(results)
-> 403
can combine lists and dictionaries to create more complex data structures or to achieve specific data organization
when checking if the value is in the list, we can use 'in' keyword
![]() | ![]() |
|---|
+) can work with dictionary as well
-cannot be indexed using sequential integer indices because they are unordered collections of key-value pairs.
-can store values of various data types as their values
![]() | ![]() |
|---|
+)
#To print smith's science score
people = [
{'name': 'bob', 'age': 20, 'score':{'math':90,'science':70}},
{'name': 'carry', 'age': 38, 'score':{'math':40,'science':72}},
{'name': 'smith', 'age': 28, 'score':{'math':80,'science':90}},
{'name': 'john', 'age': 34, 'score':{'math':75,'science':100}}
]
print(people[2]["score"]["science"])
5) def
is used when defining the function

6)tuple
ordered sequence of values
represented by a comma-delimited list whose values are enclosed in parentheses, although they're sometimes enclosed in square brackets or angle brackets.
a_dict = [('zeus','24'),('keria','29'),('faker','30')]
7)set
unordered, mutable collection of unique elements(no duplicated elements)
can perform union, intersection, difference
union
![]() | ![]() |
|---|
intersection
![]() | ![]() |
|---|
difference
![]() | ![]() |
|---|
8) f-string
as a formatted string literals, it allows for concise and dynamic expression embedding within the string using the syntax f"...".
![]() | ![]() |
|---|
9) Ternary conditional expression
condensed the original code into one line using a ternary conditional expression
In if statement
->even number
In for loop
![]() | ![]() |
|---|
10) Map & Lambda & Filter
map - a function that applies a specified operation to each item in an iterable (like a list) and returns an iterator over the results.
A lambda - way to define small, anonymous functions. It is often used in conjunction with map to apply a simple operation to each element of an iterable.
![]() | ![]() |
|---|
In the provided example, map is used to apply a lambda function to categorize individuals in the people list as either 'adult' or 'teenager' based on their age. The lambda function defines this categorization condition. The final result is a new list containing the categorization results.
filter - is used to selectively include elements from an iterable (like a list) based on a specified condition.It creates a new iterable containing only the elements that meet the specified criteria, determined by a filtering function or lambda function.
![]() | ![]() |
|---|