파이썬 객관식 심화 — 핵심 SET 02¶
이름: ____________ 점수: _____ / 100 난이도: ★★★★☆
각 코드의 실행 결과 또는 옳은 설명을 보기에서 하나 고르세요. (문항당 10점, 범위: 함수·클래스·모듈/패키지·딕셔너리·리스트·튜플·set 심화)
1. (함수) 다음 코드의 출력은?¶
x = 5
def foo(x):
x = x + 1
return x
foo(x)
print(x)
① 5
② 6
③ None
④ UnboundLocalError
⑤ Error
2. (함수) 다음 코드의 출력은?¶
def f(*args, **kwargs):
return len(args) + len(kwargs)
print(f(1, 2, 3, a=1, b=2))
① 3
② 2
③ 5
④ TypeError
⑤ 0
3. (클래스) 다음 코드의 출력은?¶
class Point:
def __init__(self, x):
self.x = x
p1 = Point(5)
p2 = Point(5)
print(p1 == p2, p1.x == p2.x)
① True True
② False True
③ True False
④ False False
⑤ Error
4. (모듈/패키지) 다음 코드의 출력은?¶
# calc.py
def add(a, b):
return a + b
if __name__ == "__main__":
print("run directly")
print(add(2, 3))
위 calc.py를 다른 파일에서 import calc로 가져왔을 때의 출력은?
① run directly 다음 5
② 5만 출력
③ 아무것도 출력 안 됨
④ run directly만 출력
⑤ Error
5. (딕셔너리) 다음 코드의 출력은?¶
d = {}
d[[1, 2]] = "value"
print(d)
① {[1, 2]: 'value'}
② TypeError
③ {}
④ KeyError
⑤ {(1, 2): 'value'}
6. (리스트) 다음 코드의 출력은?¶
a = [1, 2]
b = [1, 2]
a.append([3, 4])
b.extend([3, 4])
print(a, b)
① [1, 2, 3, 4] [1, 2, [3, 4]]
② [1, 2, [3, 4]] [1, 2, 3, 4]
③ [1, 2, 3, 4] [1, 2, 3, 4]
④ [1, 2, [3, 4]] [1, 2, [3, 4]]
⑤ Error
7. (튜플) 다음 코드의 출력은?¶
t = (5)
print(type(t))
t2 = (5,)
print(type(t2))
① <class 'tuple'> 다음 <class 'tuple'>
② <class 'int'> 다음 <class 'int'>
③ <class 'int'> 다음 <class 'tuple'>
④ <class 'tuple'> 다음 <class 'int'>
⑤ Error
8. (set) 다음 코드의 출력은?¶
s = {}
print(type(s))
① <class 'set'>
② <class 'dict'>
③ <class 'NoneType'>
④ Error
⑤ <class 'list'>
9. (클래스) 다음 코드의 출력은?¶
class Robot:
energy = 100
r = Robot()
r.energy = 80
print(r.energy, Robot.energy)
① 80 80
② 100 100
③ 80 100
④ 100 80
⑤ Error
10. (패키지) 다음 구조에서 옳은 설명은?¶
my_project/
├── main.py
└── utils/
├── __init__.py
└── string_utils.py
① __init__.py는 반드시 코드를 포함해야 패키지로 인식된다
② utils 폴더에 __init__.py가 있어야 파이썬이 패키지로 인식한다
③ string_utils.py는 패키지이다
④ main.py 없이는 utils를 패키지로 만들 수 없다
⑤ __init__.py는 string_utils.py보다 항상 먼저 실행되지 않는다