The Mojo slice __init__() function “constructs a slice given the end value”.
Syntax 1
__init__(end: Int) -> Self
Return value
It returns the constructed slice.
Syntax 2
__init__(start: Int, end: Int) -> Self
Parameters
- start (Int): The start value.
- end (Int): The end value.
Return value
It constructs the slice given the start and end values.
Syntax 3
It constructs the slice given the start, end, and step values.
__init__[T0: AnyType, T1: AnyType, T2: AnyType](start: T0, end: T1, step: T2) -> Self
Parameters
- T0 (AnyType): Type of the start value.
- T1 (AnyType): Type of the end value.
- T2 (AnyType): Type of the step value.
Return value
It returns the constructed slice.

Pranav Shah is a Cloud Engineer and completed his masters degree from MIT University.