a = 0
dots = []
while True:
a = c.find('.', a+1)
print(a)
dots.append(a) if (a != -1) else break
Why does this return an invalid syntax at the break?
a = 0
dots = []
while True:
a = c.find('.', a+1)
print(a)
dots.append(a) if (a != -1) else break
Why does this return an invalid syntax at the break?
You cannot use the conditional operator that way.
You could write something like:
is_even = True if x%2==0 else False
# or
result = foo() if should_call_foo else None
when you're deciding which of two options to assign to a variable.
But break
is a control statement and can't go here.
You probably want something using the traditional if/else approach, for example:
a = 0
dots = []
while True:
a = c.find('.', a+1)
print(a)
if (a != -1):
dots.append(a)
else:
break