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

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

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

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

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)

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

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

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

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

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

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

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

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)

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

lst = []

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

lst = [1, 2, 3]

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

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

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

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

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

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

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

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

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)

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

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

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

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

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

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

class Child(Parent):
pass

obj = Child()
print(obj.name)

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

18. 
次のコードについて、selfの適切な説明を選んでください。

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

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

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

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

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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

31. 
次のコードについて、正しい出力を選んでください。

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

class Child(Parent):
pass

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

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

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

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

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)

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

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

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

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

class Child(Parent):
pass

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

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

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

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

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

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

class Parent:
pass

class Child(Parent):
pass

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

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

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

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

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

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