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

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

animals = ["cat", "dog", "elephant"]
animals[1] = "fox"
print(animals)

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

nums = [10, 15, 20, 25, 30]
result = [x // 5 for x in nums if x % 10 == 0]
print(result)

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

t = ("a", "b", "c")
print("b" in t)

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

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

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

obj = Child()
print(obj.name, obj.age)

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

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

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

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

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

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

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

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

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

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

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

nums = [10, 20, 30, 40, 50]
print(nums[-2])

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

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

11. 
次のコードについて、selfを省略した場合の結果として正しいものを選んでください。

class MyClass:
def greet():
return "Hello!"

obj = MyClass()
print(obj.greet())

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

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
result = [row[0] + row[2] for row in matrix]
print(result)

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

words = ["apple", "banana", "cherry"]
result = [word[0].upper() + word[1:] for word in words]
print(result)

14. 
リストitems = ["pen", "pencil", "eraser", "sharpener"]の長さを取得するコードはどれでしょうか?

15. 
次のコードの説明として正しいものはどれですか?

lst = [1, 2, 3]

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

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

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

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

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

my_dict = {'a': 1, 'b': 2, 'c': 3}
reversed_dict = {v: k for k, v in my_dict.items()}
print(reversed_dict)

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

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

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

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

nums = [1, 2, 3, 4, 5]
nums[1:4] = []
print(nums)

21. 
次のコードに関して、xに格納される値として正しいものを選んでください。

my_dict = {'key1': 1, 'key2': 2, 'key3': 3}
x = my_dict.keys()

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

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

23. 
次のコードについて、Childクラスが継承している親クラスを判定する方法として正しいものを選んでください。

class Parent:
pass

class Child(Parent):
pass

print(issubclass(Child, Parent))

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

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

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

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

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

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

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

obj1 = MyClass("Alice")
obj2 = MyClass("Bob")
print(obj1.greet())
print(obj2.greet())

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

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

class Child(Parent):
def __init__(self, value):
super().__init__(value)
self.value *= 2

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

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

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

class Child(Parent):
pass

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

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

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

class Child(Parent):
pass

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

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

values = [1, 2, 3, 4, 5]
values[2] = 10
print(values)

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

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

class Child(Parent):
def greet(self):
return super().greet() + " and Child!"

class GrandChild(Child):
def greet(self):
return super().greet() + " and GrandChild!"

obj = GrandChild()
print(obj.greet())

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

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

def add(self, other_value):
return self.value + other_value

obj = MyClass(10)
print(obj.add(5))

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

lst = [1, 2, 3, 4]
lst[1:3] = [5, 6]
print(lst)

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

class MyClass:
def __init__(self):
self.data = []

def add_data(self, item):
self.data.append(item)

obj = MyClass()
obj.add_data(1)
obj.add_data(2)
print(obj.data)

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

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

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

t = (1, 2, 3)
t2 = t[:2] + (4,)
print(t2)

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

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

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

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

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

class GrandChild(Child):
pass

obj = GrandChild()
print(obj.greet())

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

nums = [2, 4, 6, 8, 10]
result = [x for x in nums if x % 3 == 0]
print(result)

40. 
次のコードについて、継承の正しい実行結果を選んでください。

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

class Child(Parent):
pass

obj = Child()
print(obj.name)

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