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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

data = [1, 2, 3, 4]
result = [x + y for x in data for y in data if x != y]
print(result)

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

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

def double(self):
self.x *= 2

obj1 = MyClass(3)
obj2 = MyClass(4)
obj1.double()
print(obj1.x, obj2.x)

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

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

class Child(Parent):
pass

obj = Child()
print(obj.name)

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

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

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

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

class Child(Parent):
pass

obj = Child()
print(obj.value)

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

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

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

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

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

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

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

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

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

class Child(Parent):
pass

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

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

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

def reset(self):
del self.value

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

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

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

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

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

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

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

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

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

def reset(self):
self.value = 0

obj = MyClass(10)
obj.reset()
print(obj.value)

21. 
次のコードについて、selfが不要なケースとして適切な説明を選んでください。

class MyClass:
@staticmethod
def static_method():
return "Static method"

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

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

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

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

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

squares = [x**2 for x in range(1, 4)]
print(squares)

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

t = (1, 2, 3)

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

letters = ['a', 'b', 'c', 'd', 'e']
print(letters[1:4])

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

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

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

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

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

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

obj = MyClass([1, 2, 3])
obj.values[0] = 10
print(obj.values)

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

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

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

lst = [1, 2, 3]

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

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

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

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

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

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

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

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

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

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)

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

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

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

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

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

40. 
次のコードについて、selfの正しい説明を選んでください。

class MyClass:
def my_method(self):
pass

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