#String

Publié le: 10 décembre 2020
sur la chaîne: Coder Decoder
2,871
114

String Slicing in Python

Python slicing is about obtaining a sub-string from the given string by slicing it respectively from start to end.
Python slicing can be done in two ways.

1. slice() Constructor
2. Extending Indexing

1.slice() Constructor
The slice() constructor creates a slice object representing the set of indices specified by range(start, stop, step).

Syntax:

slice(stop)
slice(start, stop, step)

Parameters:
start: Starting index where the slicing of object starts.
stop: Ending index where the slicing of object stops.
step: It is an optional argument that determines the increment between each index for slicing.

Python program to demonstrate
string slicing

String slicing
String ='ASTRING'

Using slice constructor
s1 = slice(3)
s2 = slice(1, 5, 2)
s3 = slice(-1, -12, -2)

print("String slicing")
print(String[s1])
print(String[s2])
print(String[s3])


Output:
String slicing
AST
SR
GITA


Sur cette page du site, vous pouvez voir la vidéo en ligne #String durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Coder Decoder 10 décembre 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 2,871 fois et il a aimé 114 téléspectateurs. Bon visionnage!