Python – Difference between Uni length slicing and Access Notation
There are various ways to extract elements, Uni length slicing and Access Notations are among them. Let’s check difference between them.
Difference #1 : Different behaviour with Different Containers
The access notation return element in both List and Strings, but return 1 length strings while slicing using uni length slice and element in case of strings.
The original list : [5, 7, 2, 6, 8, 1] The original string : 572681 The access notation result for list : 6 The access notation result for string : 6 The slicing result for list :  The slicing result for string : 6
Difference #2 : No Index out of bounds Exception in case of Slice operation
There is no out of bounds exception in case of Slice Operation, but there is, in case of access notation.
The original list : [5, 7, 2, 6, 8, 1] The access notation result for list : list index out of range The slicing result for list : 
The Time and Space Complexity for all the methods are the same:
Time Complexity: O(n)
Auxiliary Space: O(n)
My Personal Notes arrow_drop_up
Please Login to comment...