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

1. 
次のコードについて、インスタンス生成時に渡される引数の用途として正しいものを選んでください。

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

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

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

3. 
次のコードの出力として適切なのはどれでしょうか?

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

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

print("The result is {0:.1f}".format(10 / 3))

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

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

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

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

7. 
dequeで要素を先頭に追加するメソッドはどれですか?

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

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

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

a = 10
b = 3
result = a ** b % (a - b)
print(result)

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

x = 8
y = 3
print(x / y)

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

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

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

subtract = lambda x, y=5: x - y
print(subtract(10))

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

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

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

a = 5
b = 2
c = 10
result = a ** b - c / a + b * c
print(result)

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

Number: 7.0

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

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

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

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

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

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

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

from collections import deque
dq = deque(["a", "b", "c"])
dq.appendleft("z")
print(dq)

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

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

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

Total: $123.46

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

class A:
pass

class B(A):
pass

obj = B()
print(type(obj) == A)

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

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

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

Name: John, Age: 25

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

concat = lambda x, y="default": x + y
print(concat("Hello, "))

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

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

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

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

def reset(self):
self.value = 0

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

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

from collections import deque
dq = deque([10, 20, 30])
x = dq.popleft()
print(x)

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

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

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

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

class Parent:
pass

class Child(Parent):
pass

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

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

add = lambda x, y: x + y
print(add(5, 3))

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

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

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

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

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

Binary: 1101

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

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

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

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

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

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

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

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

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

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

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

x = 17
y = 5
print(x % y)

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

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

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