I thought Python supported single line if statements but I am getting an error with +=
on both Leetcode and Repl. The double line one works so I am here mostly to figure out the inner workings of Python.
Based on this question I thought this would work. I would like to know if this is a Python or platform (Leetcode or Replit) issue.
Here's my replit code which I have pasted below for posterity.
class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for num in nums:
count += 1 if len(str(num)) % 2 == 0
return count
nums = [12,345,2,6,7896]
s = Solution()
print(s.findNumbers(nums))
My error is:
File "main.py", line 8
count += 1 if len(str(num)) % 2 == 0
^
SyntaxError: invalid syntax