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

1. 
次のコードを実行したときの出力結果は何でしょうか?

square_diff = lambda x, y: (x - y) ** 2
print(square_diff(7, 5))

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

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

3. 
次のコードについて、正しい説明はどれですか?

filter_even = lambda x: x % 2 == 0
print(filter_even(5))

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

class A:
pass

class B:
pass

print(issubclass(A, (A, B)))

5. 
次のコードの出力結果は何ですか?

print("Coordinates: ({}, {})".format(23.456, 45.678))

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

from collections import deque
dq = deque([1, 2, 3])
dq.extend([4, 5])
print(dq)

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

fruits = ['apple', 'banana', 'cherry']
print(fruits[-2])

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

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

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

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

from collections import deque
dq = deque([1, 2, 3])
x = dq.popleft()
y = dq.pop()
print(dq)

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

from collections import deque
dq = deque([1, 2, 3, 4])
dq.extendleft([5, 6])
print(dq)

11. 
次のコードの出力結果は何ですか?

x = 10
y = 3
print(x + y)

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

class A:
pass

class B(A):
pass

class C(B):
pass

obj = C()
print(isinstance(obj, A))

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

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

14. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Temperature: 23.5°C

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

multiply = lambda x, y: x * y
print(multiply(3, 4))

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

class MyClass:
def __init__(self):
self.count = 0

def increment(self):
self.count += 1

obj = MyClass()
obj.increment()
obj.increment()
print(obj.count)

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

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

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

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

class A:
pass

class B(A):
pass

class C:
pass

print(isinstance(B(), A))
print(isinstance(C(), A))

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

class A:
pass

class B(A):
pass

class C(B):
pass

print(isinstance(C(), (A, B)))

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

language = "Python"
version = 3
print("I am learning {0} {1}.".format(language, version))

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

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

obj1 = MyClass(10)
obj2 = MyClass(20)
print(obj1.x + obj2.x)

22. 
次のコードについて、インスタンスの正しい説明を選んでください。

class MyClass:
pass

obj = MyClass()

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

from collections import deque
dq = deque([1, 2, 3])
dq.pop()
print(dq)

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

data = [10, 20, 30, 40, 50]
data[1:4] = [15, 25]
print(data)

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

numbers = [1, 2, 3, 4, 5]
numbers.insert(-1, 10)
print(numbers)

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

from collections import deque
dq = deque([1, 2, 3])
dq.append(4)
print(dq)

27. 
次のコードの出力結果は何ですか?

a = 7
b = 2
print(a / b * b)

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

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

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

obj = MyClass(5)
obj.double()
print(obj.value)

29. 
次のコードを実行したときの出力結果は何でしょうか?

triple_map = lambda x: list(map(lambda y: y * 3, x))
print(triple_map([1, 2, 3]))

30. 
次のコードの出力として正しいものはどれですか?

increment = lambda x: x + 1
print(increment(10))

31. 
次のコードの出力結果は何ですか?

x = 20
y = 4
z = 3
result = x % y + z ** y // x
print(result)

32. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Binary: 1101

33. 
次のコードについて、typeとisinstanceの違いに関する正しい説明を選んでください。

class Parent:
pass

class Child(Parent):
pass

obj = Child()
print(type(obj) == Parent)
print(isinstance(obj, Parent))

34. 
次のコードについて、インスタンスメソッドの正しい使い方を選んでください。

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

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

35. 
次のコードの出力結果は何ですか?

a = 15
b = 4
print(a - b)

36. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Value: +123

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

from collections import deque
dq = deque([1, 2, 3])
dq.appendleft(0)
print(dq)

38. 
次のうち、collections.dequeについて正しい説明はどれですか?

39. 
次のコードを実行したときの出力結果は何でしょうか?

calculate = lambda x, y: x * y if x > y else x + y
print(calculate(3, 5))

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

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

def reset(self):
self.value = 0

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

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