파이썬 객관식 심화 — 핵심 SET 11¶
이름: ____________ 점수: _____ / 100 난이도: ★★★★★
각 코드의 실행 결과 또는 옳은 설명을 보기에서 하나 고르세요. (문항당 10점, 범위: 함수·클래스·모듈/패키지·딕셔너리·리스트·튜플·set 심화)
1. (함수) 다음 코드의 출력은?¶
def greet(name, msg="Hello", punct="!"):
return f"{msg}, {name}{punct}"
print(greet("Kim"))
print(greet("Lee", "Hi"))
print(greet("Park", punct="?"))
① Hello, Kim! Hi, Lee! Hello, Park?
② Kim, Hello! Lee, Hi! Park, Hello?
③ Hello, Kim! Lee, Hi! Hello, Park?
④ TypeError
⑤ Hello, Kim! Hi, Kim! Hello, Park?
2. (함수) 다음 코드의 출력은?¶
def f():
pass
def g():
return None
results = [f() == g(), f() is g(), type(f()) == type(g())]
print(results)
① [True, True, True]
② [False, False, True]
③ [True, False, True]
④ Error
⑤ [None, None, True]
3. (클래스) 다음 코드의 출력은?¶
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
n3 = Node(3)
n2 = Node(2, n3)
n1 = Node(1, n2)
total = 0
cur = n1
while cur:
total += cur.value
cur = cur.next
print(total, n1.next.next.value)
① 6 3
② 6 2
③ 3 6
④ AttributeError
⑤ Error
4. (모듈/패키지) 다음 코드의 출력은?¶
import random
random.seed(5)
choices = [random.choice(["a", "b", "c"]) for _ in range(4)]
print(len(choices), set(choices).issubset({"a", "b", "c"}))
① 4 True
② 4 False
③ 3 True
④ Error
⑤ 1 True
5. (딕셔너리) 다음 코드의 출력은?¶
scores = {"kim": 90, "lee": 85}
for name in ["kim", "lee", "park", "choi"]:
scores[name] = scores.get(name, 0) + 10
print(scores)
① {'kim': 100, 'lee': 95, 'park': 10, 'choi': 10}
② {'kim': 90, 'lee': 85, 'park': 10, 'choi': 10}
③ KeyError
④ {'kim': 100, 'lee': 95}
⑤ Error
6. (리스트) 다음 코드의 출력은?¶
a = [1, 2, 3]
b = [1, 2, 3]
c = a
d = a.copy()
print(a == b, a is b, a is c, a is d)
① True False True False
② True True True True
③ False False True False
④ True False False True
⑤ Error
7. (튜플) 다음 코드의 출력은?¶
def minmax(nums):
return (min(nums), max(nums), sum(nums))
low, high, total = minmax((4, 2, 9, 1, 7))
print(low + high, total)
① 10 23
② 23 10
③ 9 23
④ 1 23
⑤ TypeError
8. (set) 다음 코드의 출력은?¶
fruits = ["apple", "banana", "apple", "cherry", "banana", "fig", "apple"]
unique = set(fruits)
counts = {f: fruits.count(f) for f in unique}
print(len(unique), counts["apple"])
① 4 3
② 5 3
③ 4 2
④ 7 3
⑤ Error
9. (함수) 다음 코드의 출력은?¶
def process(data, *, mode="default", verbose=False):
result = f"{data}-{mode}"
if verbose:
result += "!"
return result
print(process("x", mode="fast", verbose=True))
print(process("y"))
① x-fast! y-default
② x-fast y-default
③ x-default! y-default
④ TypeError
⑤ SyntaxError
10. (패키지) 다음 중 import pkg.sub와 from pkg import sub의 차이를 옳게 설명한 것은?¶
① 둘은 완전히 동일하게 동작하며 차이가 없다
② import pkg.sub는 sub라는 이름을 직접 만들지만 from pkg import sub는 만들지 않는다
③ from pkg import sub는 sub라는 이름을 직접 만들지만 import pkg.sub는 pkg라는 이름만 만든다
④ import pkg.sub는 패키지를 가져올 수 없다
⑤ from pkg import sub는 항상 에러가 발생한다