본문 바로가기
반응형

language38

[Python] 파이썬 한줄 for 문 # 한줄로 쓰는 for문 # 출석번호가 1 2 3 4였는데 앞에 100을 붙이기로 함 -> 101, 102, 103,,,,, students = [1,2,3,4,5] print(students) students = [ i+100 for i in students] print(students) # 학생 이름을 길이로 변환 students = ["Iron man", "Thor", "I am groot"] students = [len(i) for i in students] print(students) # 학생 이름을 대문자로 변환 students = ["Iron man", "Thor", "I am groot"] students = [i.upper() for i in students] print(students) 2020. 8. 28.
[Python] 파이썬 Continue 와 Break ( 제어문 ) absent = [2, 5] #결석 no_book = [7] for student in range(1, 11) : # 1~10까지 있음 if student in absent : continue # continue가 되면 아래있는 문장을 실행시키지 않고 다음 반복문 실행을 시킴 elif student in no_book : print("오늘 수업 여기까지, {0}은 교무실로 따라와".format(student)) break # 반복문을 정지시키고 종료하는 것 print("{0}, 책을 읽어봐".format(student)) 2020. 8. 27.
[Python] 파이썬 while문 반복문 customer = "토르" index = 5 while index >= 1 : #어떤 조건이 만족할 때 까지 반복하는 문 / 만족하면 탈출 print("{0}, 커피가 준비되었습니다. {1} 번 남았어요.".format(customer, index)) index -= 1 if index == 0 : print("커피는 폐기 처분되었습니다.") customer = "아이언맨" index = 1 while True : # 무한루프 print("{0}, 커피가 준비되었습니다. 호출 {1} 회.".format(customer, index)) index += 1 customer = "헐크" person = "Unknown" while person != customer : # person이 customer와 같지.. 2020. 8. 26.
[Python] 파이썬 for문 반복문 for waiting_no in [1, 2, 4, 5] : # 특정 순서있을 때 print("대기번호 : {0}".format(waiting_no)) for waiting_no in range(5) : # 특정 순서없이 순차적으로 할때 range 사용 0, 1, 2, 3, 4 ( 0~4 까지) print("대기번호 : {0}".format(waiting_no)) for waiting_no in range(1, 6) : # 1~ 6까지 print("대기번호 : {0}".format(waiting_no)) starbucks = ["아이언맨", "토르", "헐크"] for customer in starbucks : print("{0}, 커피가 준비되었습니다.".format(customer)) 2020. 8. 25.
[Python] 파이썬 if 문 weather = input("오늘 날씨는 어떄요? ") # input은 항상 문자열로 값을 받는다. # if 조건 : # 실행 명령문 if weather == "비" or weather == "눈": print("우산을 챙기세요") elif weather == "미세먼지" : print("마스크를 챙기세요") else : print("준비물이 필요 없어요.") temp = int(input("기온은 어떄요?")) if 30 2020. 8. 24.
[Python] 파이썬 자료구조의 변경 ( 리스트 / 세트 / 튜플 ) # 자료구조의 변경 # 커피숍 menu = {"커피", "우유", "주스"} # 집합으로 선언 print(menu, type(menu)) menu = list(menu) # 타입을 리스트로 변환 print(menu, type(menu)) # 결과창보면 리스트는 대괄호로 나타냄 menu = tuple(menu) print(menu, type(menu)) # 결과창 보면 튜플은 소괄호로 나타냄 menu = set(menu) print(menu, type(menu)) # 결과창 보면 세트는 중괄호로 나타냄 2020. 8. 22.