Scope and String Methods Flashcards
Outlines key concepts in scope and string methods
What is local scope?
Things defined in the current function
What does local scope include?
- All parameters of the current function
- All variables defined (assigned) anywhere within current function
What is Global scope?
All top - level definitions in the file functions and other variables
What does Global Scope include?
- All things created at no indentation
- Anything explicitly made global with a global statement
What is Built - in scope
Functions that come with Python. Such as print() and int()
When are built - in functions available?
They are always available unless a closer definition with the same name hides it.
What is the purpose of the method s.upper()?
converts letters to uppercase letters
What type of return value is associated with s.upper?
A modified copy of s
What is the purpose of s.lower()?
converts letters to lowercase letters
What type of return value is associated with s.lower()?
modified copy of s
What is the purpose of s.starswith(sval, start, end)
Identifies whether a string starts with the characters indicated in the argument
What type of return value is associated with s.starswith(sval, start, end)?
bool
What is the purpose of s. endswith(sval, start, end)?
Identifies whether a string ends with the characters indicated in the argument
What type of return value is associated with
s. endswith(sval, start, end)?
bool
What is the purpose of the method s.join(iterable)?
Concatenates items from iterable, with copies of string s in between them.
What data type is the return value of s.join(iterable)?
string result of the joined strings
What is the purpose of the method of s.split(sep)?
get list of strings obtained by splitting s into parts at each occurrence of sep
What type of return value does s.split(sep) return?
a list of strings from between occurrences of sep.
What is the purpose of the method s.replace(old, new, count)?
replace all (or count) occurrences of old str with new str
What type of return value does s.replace(old, new, count) return?
string with replacements performed
What is the purpose of the method s.strip(characters) ?
Removes the set of characters
What type of return value does s.strip(characters) return?
string with changes performed
What is the purpose of the method split()?
A built - in string method to make a string as list of substrings based on a given separator.