Common Commands & Functions Flashcards
del
(what does it do?)
deletes a variable, function, etc.
13 Common Built in String Methods & Functions Definition & Components
(upper/lower, find, index, count, length, format, replace, join, split, strip, sort , capitalize, f-strings)
( 1 )
{ }.format(value) : pass value to string
print(“Learn {a} programming”.format( a = “Python”))
you can define variables within method and asine to different positions
( 2 )
.split(separator, maxsplit) : split string based on seperator, returns a list
strVal2 = “Python : PERL” splitList2 = strVal2.split(‘:’)
( 3 )
.find(searchText, start, end ) : search text from pos.
‘Learn Python’.find(‘python’): returns -1 bec. found
( 4 )
.replace(search, replace) : replace string w/ another
( 5 )
.join(iterable) : combine strings together
( 6 )
.strip( ), lstrip( ), rstrip ( ) : removes whitespace
( 7 )
.capitalize( ) : cap. the first character of string data
( 8 )
.count(search_text, start, end) : count occurence in string
( 9 )
len(string) : total num. of characters in a string
( 10 )
.index(search_text, start, end) : search text, if not foung ValueError
( 11 )
.upper( ), .lower( ) : uppercase, lowercase string
( 12 )
f-string : add { }.format( ) directly into the string
name = “Jose”
print( f ‘Hello, my name is { name }’)
( 13 )
.sort(reverse, key) : sorts objects in alphabetical order in a string (args. are optional)
11 Common Built-In Dictionary Methods
(4) return/remove all components
(5) return/remove some components
(2) replicate or update the dictionary
Return/Remove All Components:
.keys( ) - shows all keys in a dictionary
.values( ) - shows all values
.items( ) - shows all pairings
.clear( ) - removes all dictionary elements
Return/Remove Individual Components:
.fromkeys( ) - returns a dictionary with the specified keys and values
.get( ) - returns value of the specified key
.pop( ) - removes the element with the specified key
.popitem( ) - removes last inserted key-value pair
.setdefault( ) - reutrns value from a specified key, and if key does not exist, inserts the key
Replicate/Update:
.copy( ) - copies a dictionary
.update( ) - updates the dictionary with the specified key-value pairs
11 Common Built-In List Methods
(3) update list
(3) remove elements
(2) arrange elements
(2) identify & count elements
(1) replicates a list
Update List:
.append( ) - Adds an element at the end of the list
.extend( ) - Add the elements of a list (or any iterable), to the end of the current list
.insert( ) - Adds an element at the specified position
Remove Elements From a List:
.clear( ) - Removes all the elements from the list
.pop( ) - Removes the element at the specified position
.remove( ) - Removes the first item with the specified value
Arranges List Elements:
.reverse( ) - Reverses the order of the list
.sort( ) - Sorts the list
Identify List Elements/Number of Elements:
.index( ) - Returns the value or list of values based on its order location within a list, index starts at zero
.count( ) - Returns the number of elements with the specified value
Replicate List
.copy( ) - Returns a copy of the list
2 Tuple Methods
.count( ) - returns number of times a value occurs
.index( ) - identifies items
8 Common Built-In Set Methods
(5) Edit/Remove Elements
(2) Remove/Duplicate All Elements
(4) Perform Operations Between Elements
Edit/Remove Elements from Set:
.add( ) - Adds an element to the set
.discard( ) - Remove the specified item
.pop( ) - Removes an element from the set
.remove( ) - Removes the specified element
.update( ) - Update the set with another set, or any other iterable
Remove/Duplicate All Elements from Set
.clear( ) - Removes all the elements from the set
.copy( ) - Returns a copy of the set
Operations Between Two Different Sets:
.intersection( ) - Returns a set, that is the intersection of two other sets
.difference( ) - Returns a set containing the difference between two or more sets
.symmetric_difference( ) - Returns a set with the symmetric differences of two sets
.union( ) - Return a set containing the union of sets
type conversion functions in python
- ascii() Returns a string containing a printable representation of an object
- bin() Converts an integer to a binary string
- bool() Converts an argument to a Boolean value
- chr() Returns string representation of character given by integer argument
- complex() Returns a complex number constructed from arguments
- float() Returns a floating-point object constructed from a number or string
- hex() Converts an integer to a hexadecimal string
- int() Returns an integer object constructed from a number or string
- oct() Converts an integer to an octal string
- ord() Returns integer representation of a character
- repr() Returns a string containing a printable representation of an object
- str() Returns a string version of an object
- type() Returns the type of an object or creates a new type object
type( ) function
returns the objects data type
reversed( ) function
returns the reversed iterator of a given sequence
ex. can be used to reverse the order in a for loop, instead of starting at the first item in a list, you start at the last item
next( )
returns the next item in an iterator
iter( )
converts an object into a iterator
(allows object to be iterated one element at a time)