See the example below.
In [11]: s = 'sdkzedz1'
In [12]: s[:s.rindex('z')]
Out[12]: 'sdkzed'
In [13]: s[:s.index('z')]
Out[13]: 'sdk'
String can only be extracted with numbers
To extract only adkz from adkzed, you need to write down the position of a and the position of z. Only int can fit in the location, nothing else.
s = "adkzed"
s[0:3] >> "adkz" is output
s[a:z] You can't do this. Here we're trying to find the variable value of a and the variable value of z, but these are undefined.
s = "my name is z"
s[4:] >> "ame is z" output
© 2024 OneMinuteCode. All rights reserved.