Teddy
Teddy

Reputation: 11

How to extract the keyword from str?

I am using python3 right now. I got a string over here. How do i print the -57 which is the 5th number counting from right('-' means no valid value)and print it. I have tried the many ways but don't work for me. Thank you guys.

525,03,4A5E31F,32,1850,3,5,5,A85E,-87,-8,-57,13,255,80,-

print(text[-5]) will this work?

Upvotes: 1

Views: 28

Answers (1)

Durtal
Durtal

Reputation: 1028

Split the sting after each ',' and print the 5th to last element.

my_str = '525,03,4A5E31F,32,1850,3,5,5,A85E,-87,-8,-57,13,255,80,-'
print(my_str.split(',')[-5])

Upvotes: 1

Related Questions