Skip to content

Latest commit

 

History

History
64 lines (40 loc) · 2.42 KB

Python_Extract_characters_from_string.md

File metadata and controls

64 lines (40 loc) · 2.42 KB



Template request | Bug report | Generate Data Product

Tags: #python #extract #string #character

Author: Benjamin Filly

Description: This notebook will show how to extract characters from a string.

References:

Input

Setup Variables

  • string: character string to be extracted
  • start_string: It represents the starting index position of the substring in the variable string.
  • end_string: It represents the ending index position (exclusive) of the substring in the variable string.
  • step: It determines the step or stride size used to select characters from the string. In this case, every second character is selected due to a step value of 2.
string = "Hello, World!"
start_string = 7
end_string = 12
step = 2

Model

Extract characters using index

substring = string[start_string:end_string]
substring

Extract characters using steps

steps = string[::step]
steps

Output

Display result 1

print(string)
print(f"Characters extracted from index '{start_string}' to index '{end_string}':", substring)

Display result 2

print(string)
print(f"Characters extracted every every '{step}' step started at 0:", steps)