Python
1: Print Function
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
Chapter 14: Step Argument
In this chapter, we will explore how to print characters from a string at specific intervals, also known as step-wise slicing. This allows us to extract characters in an alternating pattern or based on a defined step value. Additionally, we will learn how to reverse a string using a single argument.
Syntax: [start_index : end_index : step]
Note: If the starting and ending indices are not specified, the entire string is considered by default.
name = "Free Learning"
print(name[0:9:2]) # Alternate behaviour with start and ending parameter
Output: Fe er
print(name[0::2]) # Alternate behaviour without ending paramter
Output: Fe erig
print(name[::-1]) # Reverse String
Output: gninraeL eerF