Python String Slice Flashcards

 

card 1 of 18

 

"fabulous spectacle"[10:]

 

the number before ":" says how many characters to skip

'pectacle'

card 2 of 18

 

"fabulous spectacle"[-12]"

 

the number before ":" says where to start the slice

'us spectacle'

card 3 of 18

 

"fabulous"[-1:]"

 

the number before ":" says where to start the slice

's'

card 4 of 18

 

"fabulous"[8:]

 

the number before ":" says where to start the slice

''

card 5 of 18

 

"fabulous"[:5]

 

the number after the ":" is the limit index

'fabul'

card 6 of 18

 

"fabulous"[:-4]

 

the number after the ":" is the limit index

'fabu'

card 7 of 18

 

"fabulous"[2:5]

 

you can have "[start:limit]" for a slice

'bul'

card 8 of 18

 

"fabulous"[1:1+5]

 

expressions for indexes are evaluated first

'abulo'

card 9 of 18

 

"fabulous"[6:-1]

 

you can have "[start:limit]" for a slice

'u'

card 10 of 18

 

"fabulous"[3:3]

 

what happens when limit is not above start

''

card 11 of 18

 

"iowa"[20:2]

 

what happens when limit is not above start

''

card 12 of 18

 

"fabulous"[:6] + "fabulous"[6:]

 

each slice is evaluated first, before concatenating

'fabulous'

card 13 of 18

 

"fabulous"[6:] + "fabulous"[:6]

 

each slice is evaluated first, before concatenating

'usfabulo'

card 14 of 18

 

len("fabulous"[:-2])

 

argument of len() is evaluated first

6

card 15 of 18

 

"fabulous"[:])

 

default start is 0, but after ":" default is no limit

'fabulous'

card 16 of 18

 

(True,0,1,2,False)[2:]

 

slices on tuples are similar to strings

(1,2,False)

card 17 of 18

 

(True,0,1,2,False)[1:2]

 

slices on tuples are similar to strings

(0,)

card 18 of 18

 

(True,0,1,2,False)[-1:-1]

 

slices on tuples are similar to strings

()

 

End of Problem Set

(use browser reload to restart this problem set)