Answers for "how to slice the string in python"

12

get a slice of string in python

string = "something"

slice = string[0:3] # will be "som"
slice = string[0:-3] # will be "someth"
slice = string[3:] # will be "thing"
slice = string[:3] # same as first slice
slice = string[::2] # will be "smtig" -- it goes 2 step each time
Posted by: Guest on December-04-2020
0

Python - Slicing Strings

b = "Hello, World!"
print(b[2:5])
Posted by: Guest on February-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language