Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python usage of string and comparison

Im working with strings in python and i got an strange problem i cant explain.
My code:

print(tuple_data[11])
potting_time = tuple_data[11].split("_")[1].removesuffix('min')
print(potting_time)
     if potting_time == '0':
           print('is 0')
     else:
           print('else')

print(type(potting_time))
print(len(potting_time))

The output

Material=This_Omin
O
else
<class 'str'>
1

But if I copy the output 0 from print(potting_time) and replace the '0' at if potting_time == '0': with it and write '' by myself the output is ‘is 0’.
I thought about ' ' but the len() is 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Look closely at your inputMaterial=This_Omin . You are testing for the character before min to be a 0 when in fact it is O

So to correct your code and get the result you expect change the line of code if potting_time == '0': to read if potting_time == 'O':.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading