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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

class Parent:
pass

class Child(Parent):
pass

14. 
次のコードに関して、正しい出力結果を選んでください。

my_dict = {'a': 1, 'b': 2}
print('c' in my_dict)

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

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

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

lengths = [len(word) for word in ["apple", "banana", "cherry"]]
print(lengths)

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

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

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

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

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

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

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

words = ["hi", "hello", "hey"]
result = [w.upper() for w in words if len(w) == 3]
print(result)

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

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

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

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

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

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

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

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

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

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

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

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

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

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)

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

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

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

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

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

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

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

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

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

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

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)

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

my_dict = {'x': 10, 'y': 20, 'z': 30}
filtered = {k: v for k, v in my_dict.items() if k != 'y'}
print(filtered)

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

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

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

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

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

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

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

nums = [10, 20, 30, 40]
nums[1:3] = [100]
print(nums)

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

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

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

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

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

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