Python Conditional Remaining Operator Questions

Asked 6 days ago, Updated 6 days ago, 1 views

print('+ and -) alternately.')
n = int(input()' How many should I print?: '))

for i in range(n):
    if i % 2:
        print('-', end='')
        print('+', end='')


If you look at it

if i % 2:

I don't understand this part. If == 0 is omitted, ' -' should be printed first, but ' +' should be printed first. I'd appreciate it if you could tell me how it's printed


2022-09-20 15:16

1 Answers

If a numeric variable appears in the conditional expression,

True if any value exists,

If there is no value, (0) False.

2022-09-20 15:16

If you have any answers or tips

© 2022 pinfo. All rights reserved.