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

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

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

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

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

class Child(Parent):
pass

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

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

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

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

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

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

my_dict = {'a': 1, 'b': 2}
my_dict['c'] = 3
print(len(my_dict))

5. 
リストnumbers = [1, 2, 3, 4, 5]のすべての要素を取得するにはどうすればよいでしょうか?

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

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

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

my_dict = {'a': 1, 'b': 2, 'c': 3}
del my_dict['b']
print(my_dict)

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

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

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

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

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

t = (1, 2, 3)

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

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

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

doubles = [x*2 for x in range(3)]
print(doubles)

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

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

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

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)

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

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)

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

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

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

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

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

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

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

class Parent:
def __init__(self):
self.data = [1, 2, 3]

class Child(Parent):
def __init__(self):
super().__init__()
self.data.append(4)

obj = Child()
print(obj.data)

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

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

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

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

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

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

class Child(Parent):
pass

obj = Child()
print(obj.value)

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

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

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

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())

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

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

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

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

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

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

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

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

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

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

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

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

data = [10, 20, 30, 40]
result = [data[i] + data[i+1] for i in range(len(data)-1)]
print(result)

30. 
次のコードについて、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"))

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

numbers = [5, 10, 15, 20, 25]
numbers[0:3] = [1, 2]
print(numbers)

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

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

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

data = [[1, 2], [3, 4], [5, 6]]
result = [x[1] for x in data]
print(result)

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

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

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

uppercase = [char.upper() for char in "abc"]
print(uppercase)

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

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

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

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

class Child(Parent):
pass

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

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

values = [1, 2, 3, 4, 5]
new_values = [val for val in values if val > 3]
print(new_values)

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

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

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

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

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

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