Computer Science Udacity Flashcards
In the source code how do we know it’s a URL
<a> This is Wiki clickable link text </a>
<a></a>
What is an edge case?
s =string
If s is the ‘’ empty string, then s[0] will cause an error because there is no character at position
This is called an edge case in programming. It’s a situation that doesn’t come up too often (you usually don’t need to use an empty string), but it does happen sometime.
It’s easy to forget about edge cases and doing so is a common cause of bugs.
What is the subsequence operator
The colon :
eg # Given the variables s and t defined as: s = 'udacity' t = 'bodacious' # write Python code that prints out udacious # without using any quote characters in # your code. print s[:5] + t[6:] # prints 'udacious' # or print s[:-2]+t[:-3] # Count from the end
Give an example of using the .find method
# Assume text is a variable that # holds a string. Write Python code # that prints out the position # of the first occurrence of 'hoo' # in the value of text, or -1 if # it does not occur at all.
text = “first hoo”
ENTER CODE BELOW HERE
print text.find(“hoo”)
Assume text is a variable that
holds a string. Write Python code that prints out the position of the second occurrence of ‘zip’ in text, or -1 if it does not occur at least twice.
ans = 18
# Here are two example test cases: text = 'all zip files are zipped'
# >>> 18 # text = 'all zip files are compressed' # >>> -1
first_zip = text.find(‘zip’)
print text.find(‘zip’, text.find(‘zip’)+1)
or
print text.find(‘zip’, text.find(‘zip’) + 1
This finds the first ‘zip’ and they starts looking 1 character after it for the other ‘zip’
How can you read a string backwards?
You can read a string backwards with the following syntax string[::-1] - where the “-1” means one step back.