목록전체 글 (37)
돌맹이

입, 출금 및 잔고 확인을 할 수 있는 간단한 프로그램을 만들어보자 public class HumanExam10 { public static void main(String[] args) { boolean run = true; int balance = 0; Scanner scanner = new Scanner(System.in); while(run) { System.out.println("-----------------------------"); System.out.println("1.예금 | 2.출금 | 3.잔고 | 4.종료"); System.out.println("-----------------------------"); System.out.println("선택 > "); int choice = sca..
o가 들어간 단어만 추출하여 새로운 list를 만들어보자 ## 일반 문법을 사용한 반복문 a = ['computer','apple','human','zoo','country'] result_list=[] for x in a: if "o" in x: result_list.append(x) print(result_list) ['computer', 'zoo', 'country'] ## Pythonic을 사용한 반복문 a = ['computer','apple','human','zoo','country'] result_list2 = [x for x in a if 'o' in x] print(result_list2) ['computer', 'zoo', 'country'] 두 코드의 결과값은 같다. Python에서 ..
list와 tuple은 파이썬의 자료형으로 array값을 나타낼 때 사용한다. 두 자료형은 구조와 쓰임새가 비슷하지만 차이점도 존재한다. 공통점 1. indexing과 slicing이 가능 2. 둘다 iterable(반복 가능)함 차이점 1. list는 수정 가능(mutable) 하지만 tuple은 수정 불가능(immutable)