[python]continue,break,1行for文



1.conntinue,break,行為文

#continue & break : 반복문에서 사용
absent = [2,5] #결석
no_book = [7] #책없음
for student in range(1,11):
    if student in absent:
        continue #계속하기
    elif student in no_book :
        print("오늘 수업 여기까지.{0}는 교무실오렴".format(student))
        break #반복문 종료
    print("{0},책읽어라.".format(student))

#한줄로 끝내는 for
#출석번호가 1,2,3,4... 앞에 100 붙이기로함
students  = [1,2,3,4,5]
print(students)
students = [i+100 for i in students]
print(students)

#학생 이름을 길이로 변환
students2 = ["kuro","adonis","nagisa","rinne"]
students2 = [len(i) for i in students2]
print(students2)  #-> [4,6,6,5]

#학생 이름을 대문자로 변환
students3 = ["kuro","adonis","nagisa","rinne"]
students3 = [i.upper for i in students3]
print(students3)