파이썬 - if not : continue

Euisub Jung (Santa)·2021년 10월 30일
0

if not A :
   continue
B

루프문에서 사용하면, A를 찾을때만 B를 실행한다.
continue는 이번 루프를 skip하라는 의미이다.

# Use the file name mbox-short.txt as the file name
fname = input("Enter file name: ")
fh = open(fname)

s = 0
n = 0

for line in fh:
    if not line.startswith("X-DSPAM-Confidence:"):
        continue
    # print(line)
    pos = line.find("0")
    num = line[pos:]
    fnum = float(num)
    s = s + fnum
    n = n + 1
    # print(fnum)

print("Average spam confidence:", s / n)

# print("Done")
profile
오늘부터 개발자

0개의 댓글