Python 3エンジニア認定基礎試験~模擬試験⑤~

1. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3)
a, b, c = t
print(b)

2. 
次のコードについて、子クラスで親クラスのメソッドをオーバーライドした場合の正しい出力を選んでください。

class Parent:
def greet(self):
return "Hello from Parent!"

class Child(Parent):
def greet(self):
return "Hello from Child!"

obj = Child()
print(obj.greet())

3. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, value):
self.value = value

def multiply(self, factor):
self.value *= factor

obj = MyClass(5)
obj.multiply(3)
print(obj.value)

4. 
次のコードの出力は何でしょうか?

lst = [1, 3, 5, 7]
result = [x * y for x in lst for y in lst if x != y]
print(result)

5. 
次のコードの出力は何でしょうか?

numbers = [1, 2, 3, 4, 5, 6]
numbers[1:5:2] = [7, 8]
print(numbers)

6. 
次のコードについて、親クラスのコンストラクタを子クラスで明示的に呼び出す正しい方法を選んでください。

class Parent:
def __init__(self, name):
self.name = name

class Child(Parent):
def __init__(self, name, age):
super().__init__(name)
self.age = age

obj = Child("Alice", 10)
print(obj.name, obj.age)

7. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3, 4)
print(t.index(3))

8. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3]
lst.insert(1, 4)
print(lst)

9. 
以下のコードの出力結果を選んでください。

my_dict = {'a': 10, 'b': 20, 'c': 30}
print(my_dict.get('d', 'Not Found'))

10. 
次のコードの出力は何でしょうか?

lst = [10, 20, 30]
result = [x + y for x in lst for y in lst if x != y]
print(result)

11. 
次のコードの出力は何ですか?

data = [5, 3, 9, 1]
data.sort(reverse=True)
print(data)

12. 
次のコードの実行結果を選んでください。

my_dict = {'x': 10, 'y': 20}
copied_dict = my_dict.copy()
copied_dict['x'] = 100
print(my_dict, copied_dict)

13. 
次のコードの実行結果を選んでください。

class Parent:
def __init__(self, value):
self.value = value

class Child(Parent):
pass

obj = Child(20)
print(obj.value)

14. 
次のコードの実行結果を選んでください。

my_dict = {'a': 1, 'b': 2, 'c': 3}
keys = list(my_dict.keys())
values = list(my_dict.values())
print(keys[1], values[1])

15. 
次のコードを実行した場合、出力は何ですか?

lst = [3, 1, 4, 1, 5, 9]
lst.reverse()
print(lst)

16. 
次のコードの出力は何ですか?

values = [1, -2, 3, -4, 5]
result = [abs(x) for x in values if x < 0]
print(result)

17. 
次のコードを実行した場合、出力は何ですか?

t = tuple("abc")
print(t)

18. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3, 4]
print(lst[-3])

19. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3)
print(t[1])

20. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3]
lst.extend([4, 5])
print(lst)

21. 
次のコードの実行結果を選んでください。

my_dict = {'a': 10, 'b': 20}
new_dict = {key: my_dict.get(key, 0) + 5 for key in ['a', 'c']}
print(new_dict)

22. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3]
lst *= 2
print(lst)

23. 
次のコードについて、Childクラスに追加された属性が正しく設定されているか確認する方法を選んでください。

class Parent:
def __init__(self, name):
self.name = name

class Child(Parent):
def __init__(self, name, age):
super().__init__(name)
self.age = age

obj = Child("Alice", 10)
print(hasattr(obj, "age"))

24. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3, 4]
del lst[2]
print(lst)

25. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3) + (4, 5)
print(t)

26. 
次のコードについて、selfの使用方法として正しいものを選んでください。

class MyClass:
def __init__(self, name):
self.name = name

def greet(self):
return f"Hello, {self.name}!"

27. 
次のコードの出力は何でしょうか?

nums = [1, 2, 3, 4, 5]
result = [x**2 for x in nums if x % 2 == 0]
print(result)

28. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3)
t[1] = 4

29. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3)
print(len(t))

30. 
次のコードの出力は何ですか?

words = ["hi", "hello", "hey"]
result = [w.upper() for w in words if len(w) == 3]
print(result)

31. 
次のコードの実行結果を選んでください。

class MyClass:
def set_value(self, value):
self.value = value

obj = MyClass()
obj.set_value(42)
print(obj.value)

32. 
次のリスト内包表記の出力は何でしょうか?

evens = [x for x in range(10) if x % 2 == 0]
print(evens)

33. 
次のコードの実行結果を選んでください。

class Parent:
def __init__(self):
self.value = 10

class Child(Parent):
pass

obj = Child()
print(obj.value)

34. 
次のコードの実行結果を選んでください。

my_dict = {'x': 10, 'y': 20, 'z': 30}
filtered = {k: v for k, v in my_dict.items() if k != 'y'}
print(filtered)

35. 
次のコードに関して、正しい出力結果を選んでください。

my_dict = {'a': 1, 'b': 2}
print('c' in my_dict)

36. 
Pythonのディクショナリについて正しいものを選んでください。

37. 
次のコードの実行結果を選んでください。

class Parent:
def __init__(self, name):
self.name = name

def greet(self):
return f"Hello, {self.name}!"

class Child(Parent):
def greet(self):
return f"Hi, {self.name}!"

obj = Child("Alice")
print(obj.greet())

38. 
次のコードを実行した場合、出力は何ですか?

lst = [1, 2, 3]
print(len(lst))

39. 
次のコードを実行した場合、出力は何ですか?

t = (1, 2, 3, 4, 5)
print(t[-2])

40. 
次のコードを実行した場合、出力は何ですか?

t = tuple(range(5))
print(t)

コメントを残すにはログインしてください。