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

What are the differences between strings 'True','False' and boolean True,False in Python

sorted_varieties = price_extremes.sort_values(by =['min','max'], ascending = ['False','False'])
variety min max
Pinot Grigio 4.0 70.0
Malbec-Syrah 4.0 78.0
White Blend 4.0 375.0
Tempranillo 4.0 600.0
sorted_varieties = price_extremes.sort_values(by =['min','max'], ascending = [False,False])
variety min max
Ramisco 495.0 495.0
Terrantez 236.0 236.0
Francisa 160.0 160.0
Rosenmuskateller 150.0 150.0

I got two different sorted values when I passed the ascending arguments in the list format of booleans in string and boolean formats. I expected to run into an error if I passed Boolean values as strings. But the code got executed without any error. How do the booleans in string 'True','False' differ from boolean True, False values in execution?

>Solution :

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

A non-empty string evaluates as True, so in your case it is similar to running:

sorted_varieties = price_extremes.sort_values(by=['min','max'],
                                              ascending=[True, True])
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