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

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

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

obj = MyClass(10)

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

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

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

class MyClass:
pass

obj = MyClass()
print(isinstance(obj, MyClass))

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

mod = lambda x, y: x % y
print(mod(10, 3))

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

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

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

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

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

data = [0, 1, 2, 3, 4]
data[1:3] = [8, 9]
print(data)

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

class A:
pass

class B:
pass

print(issubclass(B, A))

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

Binary: 1101

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

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

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

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

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

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

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

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

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

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

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

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

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

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

obj = MyClass("Bob")
del obj.name
print(obj.name)

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

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

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

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

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

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

19. 
次のコードで、変数x = 10を埋め込んで「Value: 10」と出力するための正しい記述はどれですか?

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

age = 25
print("I am {} years old".format(age))

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

x = 6
y = 7
z = 2
result = x ** z // y + x % z
print(result)

22. 
Pythonで文字列の書式指定に使用するメソッドとして正しいものはどれですか?

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

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

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

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

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

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

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

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

repeat = lambda s, n: s * n
print(repeat("A", 3))

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

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

29. 
リストの長さを取得するには、どの関数を使用しますか?

data = [3, 6, 9, 12]
# リストの長さを取得するコード

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

class Parent:
pass

class Child(Parent):
pass

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

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

class A:
pass

class B(A):
pass

class C(B):
pass

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

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

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

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

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

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

square = lambda x: x ** 2
print(square(4))

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

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

36. 
以下のコードの出力は何でしょうか?

a = [1, 2, 3]
b = [4, 5]
print(a + b)

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

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

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

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

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

concat = lambda s1, s2: s1 + " " + s2
print(concat("Hello", "World"))

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

a = 2
b = 4
print(a ** b)

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