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

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

class MyClass:
class_variable = "shared"

MyClass.class_variable = "modified"
print(MyClass.class_variable)

2. 
divmod(10, 3)の出力結果はどれですか?

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

class MyClass:
class_variable = 10

4. 
文字列s = "abcdefghij"の最初の5文字を逆順で取得するスライスはどれですか?

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

s = "abcdefghij"
print(s[2:9:3])

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

def calculate_area(length=5, width=3):
return length * width

print(calculate_area(width=4))

7. 
文字列s = "abcdefghij"のインデックス1から8までを逆順で取得するために使用するスライスはどれですか?

8. 
次のうち、Pythonで整数を定義する正しい文はどれですか?

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

try:
print("Start")
finally:
print("Cleanup complete")

10. 
次のコードを実行した場合、出力結果として正しいものを選んでください。

def show_info(name="John", age=25):
print(f"{name} is {age} years old.")

show_info(age=30)

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

class MyClass:
class_attribute = "shared"

obj1 = MyClass()
obj2 = MyClass()

obj1.class_attribute = "modified"
print(obj2.class_attribute)

12. 
int("101", 2)の結果はどれですか?

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

class MyClass:
class_variable = 0

@classmethod
def increment(cls):
cls.class_variable += 1

obj1 = MyClass()
obj2 = MyClass()

obj1.increment()
obj2.increment()
print(MyClass.class_variable)

14. 
次のコードで、finallyブロックが実行される理由として正しいものを選んでください。

try:
print("Try block")
except:
print("Except block")
finally:
print("Finally block")

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

s = "abcdefgh"
print(s[1:6:2])

16. 
デフォルト値として設定できるオブジェクトに該当しないものはどれですか?

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

class MyClass:
class_variable = 10

obj1 = MyClass()
obj2 = MyClass()
obj1.class_variable = 20

print(MyClass.class_variable)

18. 
bin(10)の出力はどれですか?

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

def divide(a, b=1):
return a / b

print(divide(10, b=2))

20. 
次のコードに関する正しい説明はどれですか?

def append_item(item, items=[]):
items.append(item)
return items

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

def greet(name, message="Welcome", punctuation="!"):
return f"{message}, {name}{punctuation}"

print(greet("Alice", punctuation="!!!"))

22. 
int("20")の結果は次のどれですか?

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

class MyClass:
class_attribute = "shared value"

24. 
以下のコードの出力はどれですか?

num = 1_000_000
print(num)

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

s = "1234567890"
print(s[-4:])

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

class MyClass:
def instance_method(self):
print("This is an instance method")

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

def introduce(name, age, city="Unknown"):
return f"{name} is {age} years old and lives in {city}."

print(introduce("Sam", 30))

28. 
hex(255)の出力はどれですか?

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

def power(base, exponent=2):
return base ** exponent

print(power(3, exponent=3))

30. 
次のコードについて、staticmethodの役割として正しいものを選んでください。

class MyClass:
@staticmethod
def my_static_method():
print("This is a static method")

31. 
次のコードを実行した場合、結果は何になりますか?

def add_numbers(a, b=10, c=5):
return a + b + c

print(add_numbers(1, c=2))

32. 
Pythonで文字列s = "Hello World"の最初の5文字を取得するスライスはどれですか?

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

class MyClass:
class_variable = "shared"

obj = MyClass()
obj.class_variable = "instance value"
print(MyClass.class_variable)

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

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

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

35. 
次のコードについて、クラス変数へのアクセス方法として正しいものを選んでください。

class MyClass:
class_variable = "shared"

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

def customize_greeting(name="Guest", greeting="Welcome"):
return f"{greeting}, {name}!"

print(customize_greeting(greeting="Hello"))

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

class MyClass:
class_variable = {"key": "value"}

obj = MyClass()
obj.class_variable["new_key"] = "new_value"

print(MyClass.class_variable)

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

def format_message(message, prefix="Info: ", suffix="."):
return f"{prefix}{message}{suffix}"

print(format_message("System update completed", suffix="!"))

39. 
次のコードについて、obj1.class_variable = "changed"の動作として正しいものを選んでください。

class MyClass:
class_variable = "shared"

obj1 = MyClass()
obj2 = MyClass()
obj1.class_variable = "changed"
print(obj2.class_variable)

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

class MyClass:
class_variable = 5

def change_variable(self):
self.class_variable += 1

obj1 = MyClass()
obj2 = MyClass()

obj1.change_variable()
print(MyClass.class_variable)

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