-3

i want to leave '' vacant number from list and print data

numbers= ['123','456','','789']

I want result like this:

123
456
789
rdas
  • 20,604
  • 6
  • 33
  • 46
Abhay
  • 1
  • 2

2 Answers2

-1

Check if the string in numbers is empty or not with if

for num in numbers:
    if num:
        print(num)

'' - the empty string is False-ey so it won't be printed

rdas
  • 20,604
  • 6
  • 33
  • 46
-2

Using a for loop and an if statement to catch empty strings, you could do the following:

for number in numbers:
    if not number:
        continue
    else:
        print(number)


# prints this
123
456
789
C.Nivs
  • 12,353
  • 2
  • 19
  • 44