1/28
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
get length of string
print(len())
string mutable or not
immutable
unless:
using +=
id() function
The id() function returns the object's memory address
lexicographical order
ord()
use ASCII table
isalnum(), isalpha(), isdigit()
Return True if string is alphanumeric.
Return True if string contains only letters.
Return True if string contains only digits.
isidentifier()
Checks whether a string would be a valid name for a variable
Returns true or false
islower(), isupper(), isspace()
Return True if string is in lowercase or changes word to lower
Return True if string is in uppercase or changes word to upper
Return True if string contains only white space.
endswith(s1), startswith(s1)
Return True if string ends with sub-string s1.
Return True if string starts with sub-string s1.
count(s1),find(s1),rfind(s1)
Return number of s1’s
Return lowest index from where string s1
Return highest index from where string s1
print(s.capitalize()) ,print(s.title()) ,print(s.replace("trix", "d"))
cap the first letter
cap the first letter of both words
replace the given var
list
A list contains multiple items of any type. It is mutable and its contents can be manipulated. lists are dynamic items can be added or removed
list uses [brackets]
add items to list
append() to add an item at end of the list
insert() to insert a item at the specified index
delete item
pop() to remove item (by position) from the list
remove() to remove item (by content) from the list
clear() to remove all items from the list
max(list), min(list), sum(list),del(list)
Returns the max value within the list
Return the minimum value within the list
Return the sum of all the items in the list
Deletes the list
index(item), count(item),insert(index, item)
Return the index of the first element whose value is equal to the item
counts number of values
Insert the item into the list at the specified index
sort(), reverse()
Sort the items in the list in ascending order.
Reverse the order of the items in the list
pop(), remove(item), clear()
remove item at the specified index
Remove the first item from the list
Remove all the contents in the list
copy list content
by
slicing
operator 1 to duplicate the full content
copy() to make a copy of the content
A list() constructor is a built-in function which can be used to convert an iterable
tuple
A tuple contains multiple items of any type.it is immutable and Tuples are more efficient in terms of performance and memory usage since they are immutable
uses (bracket)
tuple methods
Tuples only support index() and count() methods.
how to tuple to list
tuple( listName )
reverse
list( tupleName )
dictionary
A dictionary stores a collection of data. Each item in a dictionary has two parts: a key and a value. Dictionaries are mutable and their contents are immutable.
uses {bracket}
when to uss [bracket] in dictionary
The square bracket [] and the key is used to retrieve value from a dictionary. It is also used to :
update value in the dictionary
add a new value to the dictionary
sorted()
use sorted() to create a sorted list of key
for key in sorted( dic.keys() ) : #returns keys sorted in a list
print( key , ":" , dic[ key ] )
Output:
Abe : Boss
Bob : Cook
Nat : Staff
Pete : Chef
list in dict
print( f"Jerome's Math mark : { examResult['Jerome'][1] } " )
dict in dict
print( f"Jerome's Math mark : { examResult['Jerome']['Math'] } " )
list in list
print( f"Jerome's Math mark : { examResult[2][2] } " )
while loop vs for loop
while It is a condition-controlled loop. The loop will keep executing until the condition becomes false.
for It is a count-controlled loop
break statement
The break statement ends the current loop and jumps to the statement immediately following the loop.
continue statement
The continue statement ends the current iteration and jumps to the top of the loop and starts the next iteration.