Lecture 2 Flashcards
Mutable vs. non-mutable, string methods, tuples, string concatenation
mutable objects definition
can be changed after they are created, like lists or dictionaries
immutable objects definition
cannot be changed after they are created, such as strings, integers, or tuples.
string slicing definition
obtaining a sub-string from the given string by slicing it respectively from start to end
string slicing: array method. syntax
string_name[beginning:end:step]
*note that you can also index backwards in the steps parameter
how do you reverse a string?
stringname[::-1]
slice() constructor (syntax and what it does)
- Returns a sliced object containing elements in the given range only.
- slice(stop)
OR
slice(start, stop, step)
how do you slice a list?
listname[start, stop, step]
count method for strings
stringname.count(“stringtosearch”)
returns number of occurrences of argument in stringname.
what does the index method do when used on a string and what is the syntax?
stringname.index(“character”)
returns the index of the character in argument
NOTE that it will not work with strings, singular characters only!!!!!!!
what does the split method do to a string and what is the syntax?
stringname.split(delimeter, max splits)
splits every item in the string, returns a list
join method syntax and what it does
joiner.join(sequencetojoin)
joins every element in a sequence uisng the joiner. returns a string.
isdigit and isalpha
syntax and use
check if argument passed is numerical or alphabetical, returns true or false
tuple definition
An ordered collection or grouping of items.
cna you type cast a list into a tuple and vice versa?
YES!
How do you access the elements in a tuple?
same way you do in a list, by indexing