Computer Science Udacity Flashcards

1
Q

In the source code how do we know it’s a URL

A

<a> This is Wiki clickable link text </a>

<a></a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an edge case?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the subsequence operator

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of using the .find method

A
# 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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you read a string backwards?

A

You can read a string backwards with the following syntax string[::-1] - where the “-1” means one step back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly