File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -546,6 +546,31 @@ which is the average inflammation per patient across all days.
546546> > Creates a substring from index 1 up to (not including) the final index,
547547> > effectively removing the first and last letters from 'oxygen'
548548> {: .solution}
549+ >
550+ > How can we rewrite the slice for getting the last three characters of `element`,
551+ > so that it works even if we assign a different string to `element`?
552+ > Test your solution with the following strings: `carpentry`, `clone`, `hi`.
553+ >
554+ > > ## Solution
555+ > > ~~~
556+ > > element = 'oxygen'
557+ > > print('last three characters:', element[-3:])
558+ > > element = 'carpentry'
559+ > > print('last three characters:', element[-3:])
560+ > > element = 'clone'
561+ > > print('last three characters:', element[-3:])
562+ > > element = 'hi'
563+ > > print('last three characters:', element[-3:])
564+ > > ~~~
565+ > > {: .language-python}
566+ > > ~~~
567+ > > last three characters: gen
568+ > > last three characters: try
569+ > > last three characters: one
570+ > > last three characters: hi
571+ > > ~~~
572+ > > {: .output}
573+ > {: .solution}
549574{: .challenge}
550575
551576> ## Thin Slices
You can’t perform that action at this time.
0 commit comments