Answers for "string slicing [::-1]"

12

python string slicing

my_string = "Hey, This is a sample text"
print(my_string[2:]) #prints y, This is a sample text
print(my_string[2:7]) #prints y, Th excluding the last index
print(my_string[2::2]) #prints y hsi  apetx
print(my_string[::-1]) #reverses the string => txet elpmas a si sihT ,yeH
Posted by: Guest on May-03-2020
0

String Slices

s = 'Hello'
  #    01234    ## Showing the index numbers for the 'Hello'
  s[1:4]  ## 'ell' -- starting at 1, up to but not including 4
  s[0:2]  ## 'He'
Posted by: Guest on May-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language