aditya aditya - 1 year ago 73
Python Question

Difference Between True and true

I was practicing a pyhton related problem at Hackerrank. I am a total newbie to pyhton. The Problem was to simply write a function, which checks if a year is leap year or not according to the Gregorian calendar.

I looked in the discussions tab, where I found out the answer, I decided to not to copy up the code and instead I wrote the code after understanding it.

So I wrote it this way:

if year%4 == 0 and (year%100 != 0 or year%400 == 0):
leap = true;

When I ran the tests, It ended up with two failed tests and two timed out tests. So I checked the solution in the discussions tab again and changed my code to:

if year%4 == 0 and (year%100 != 0 or year%400 == 0):
leap = True

When I ran this code, all my test cases passed, without any errors.

Does python have only 'True' and not 'true'?

Thank you in advance. :)

Answer Source

True is capitalised because Python built in constants are capitalised:

"true" would create an error, as the program will be looking for a non-existant variable called true.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download