M
M
MaxLoL03772020-08-10 16:21:48
Python
MaxLoL0377, 2020-08-10 16:21:48

How to remove excess from output in Python?

I have a piece of code that takes a value from a range of lines in the text:

for i in range(19, 25):
    x = (sheet.cell(row=i, column=2).value)
    if x != "None":
        print(x)
    else : break

The output looks like:
Значение 1 
Значение 2 
...
None
None
None

I understand that the code is not entirely correct, because X in any case is not equal to None, because the first value is always present and the code works exactly as I wrote it. Please help me either process the output by stripping None out of it, or amend the code so that it picks up only those lines that have values.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2020-08-10
@MaxLoL0377

Wrap the code in a tag when you ask a question.
The condition should be like this:

if x:
    print(x)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question