1.3 Quick Solution, Can Anyone do It with Less Code ;)?
Here you have, and I’m just curious to see if you can solve it using even a character less:
def is_int(x):
if x%1: return False
else: return True
Ok, as lame as I could appear, I’ve just beated myself googline for “ternary operator in python” and ending up with this code:
def is_int(x):
return False if x%1 else True
I’m fond of finding always new ways to do with less, so if anyone finds an even shorter working code, I’m with it :)!
Edit: Micheal Rochlin awesome idea is just:
def is_int(x):
return x%1==0
Kudos to him :)
Answer 5149c4dfbaf2fa33320029a7
2 comments
Very nice!
Beated :D!
I edited my message to give you credit ;)
Answer 5149e4443902fa7ad8003297
0 votes
Is there a way to do your if statements with true first, then false? Part of me is a little ocd about doing the statement with returning false first.
Submitted by anonymous
almost 13 years
1 comments
Just put a “not” in front of the condition :)
Popular free courses
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.4 Lessons
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.11 Lessons
- Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
- Beginner Friendly.6 Lessons