-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
  • 18,048
  • 6
  • 31
  • 42
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
  • 18,048
  • 6
  • 31
  • 42
-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
  • 10,555
  • 2
  • 17
  • 39