Skip to main content

Posts

Showing posts with the label slicing

Slicing in Python

  * Let's first understand how a slicing is been done-- Consider a string namely==>> string = 'python_developer!' If we print this then-- #  Output: python_developer! >> Now lets do some slicing here-- print (string[0:17:2]) >> Then the-- # Output: pto_eeoe! >> Lets see how it works-- So basically the print statement is in the form of  print(string[a:b:c]) >>  Now here   --           a: Starting position b: Ending position c: Steps taken >> If we take out length of the given string then-- print (len(string)) # Output: 17 * The total length of the given string is 17. Therefore in our given problem the string will be printed from 0 index to 16 index and would take 2 steps. >> Hence the output-- # Output: pto_eeoe! >> Now the print statement that we have used here is-- print (string[0:17:2]) >> We can also use-- print (string[:17:2]) >> It will give the same output-- # Output: pto eeoe! >> But what if