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

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

my_dict = {'x': 10, 'y': 20, 'z': 30}
result = {key: val * 2 for key, val in my_dict.items() if val > 15}
print(result)

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

nums = [5, 10, 15, 20]
result = [x / 5 for x in nums if x > 10]
print(result)

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

lst = [10, 20, 30]
new_lst = lst.copy()
new_lst.append(40)
print(lst, new_lst)

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

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

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

fruits = ["apple", "banana", "cherry"]
print(fruits[1])

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

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

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

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

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

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)

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

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

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

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

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

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

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

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

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

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

my_dict = {i: i**2 for i in range(3)}
print(my_dict)

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

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

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

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

class Child(Parent):
pass

class GrandChild(Child):
pass

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

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

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

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

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

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

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

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

class Parent:
pass

class Child(Parent):
pass

print(issubclass(Child, Parent))

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

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

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

squares = [x**2 for x in range(5)]
print(squares)

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

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

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

my_dict = {'x': 10, 'y': 20}
result = [(k, v) for k, v in my_dict.items()]
print(result)

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

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

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

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

letters = [char for char in "hello"]
print(letters)

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

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

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

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

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

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

obj1 = MyClass(10)
obj2 = obj1
obj2.value = 20
print(obj1.value)

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

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

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

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

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

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

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

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

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

my_dict = {'x': 10, 'y': 20, 'z': 30}
my_dict.clear()
print(my_dict)

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

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

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

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

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

my_dict = {'a': 100, 'b': 200, 'c': 300}
removed_value = my_dict.pop('b', 'Key not found')
print(removed_value, my_dict)

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

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

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

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

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

t = (5,)

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

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

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

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

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

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

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