[Java/Python] 문법 비교 정리 #6 자료구조 - Set
Java에서의 Set Set a = new HashSet(Arrays.asList(1, 3, 2, 4, 8, 9, 0)); Set b = new HashSet(Arrays.asList(1, 3, 7, 5, 4, 0, 7, 5)); // 합집합 Set union = new HashSet(a); union.addAll(b); System.out.println(union); // 0, 1, 2, 3, 4, 5, 7, 8, 9 // 교집합 Set intersection = new HashSet(a); intersection.retainAll(b); System.out.println(intersection); // 0, 1, 3, 4 // 차집합 Set difference = new HashSet(a); diff..
2022. 11. 8.
[Python] 함수 정의 하기
1. 함수 정의 하기 def f(a, b, c, d): print(f"{a + b}, {c + d}") f(c=1,d=5,a=3,b=7) # 결과 10, 6 2. default 인자 정의하기 def f(a=1, b, c=1, d): print(f"{a + b}, {c + d}") f(b=3, d=7) # 결과 4, 8 3. 참조 인자 위치 강제 하기 인자의 key를 인자에 적용하여 함수를 호출하면 순서에 상관없이 인자를 입력할 수 있습니다. 하지만 /를 인자 사이에 선언하면 / 앞에 위치한 인자의 위치를 강제시킬수 있습니다. def f(a, b, /, c, d): print(f"{a + b}, {c + d}") f(3,6,1,1) # 결과 9, 2 # Type Error 발생하는 경우 f(c=3,d=6,..
2022. 11. 3.