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

1. 
Pythonの対話モードで、直前に実行したコードを再度実行するにはどうすればよいですか?

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

a = [1, 2, 3]
b = a
b.append(4)
print(a)

3. 
Pythonのバージョン3.x系で追加された、テキストのエンコーディングに関する標準規格は何ですか?

4. 
関数greetに名前を渡し、「Hello, 名前!」と出力する関数を正しく定義する方法はどれでしょうか?

5. 
Pythonが「インデントによってコードブロックを区切る」仕組みは、どのような利点と欠点を持っていますか?

6. 
Pythonの「標準ライブラリ」に含まれていないものはどれですか?

7. 
Pythonの創始者である「グイド・ヴァンロッサム」が、Pythonの開発を始めたきっかけとなったのはどの言語の後継を意識したからですか?

8. 
次のコードで、関数subtractが呼び出されたときに引数が指定されなければxとyにそれぞれ0が入るように設定する方法はどれでしょうか?

9. 
次のJSON形式のデータをPythonの辞書に変換するために使用する関数を選んでください。

{
"name": "Alice",
"age": 25,
"city": "Tokyo"
}

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

def greet(name="Guest"):
return "Hello, " + name + "!"

print(greet())
print(greet("Alice"))

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

x = 5
y = "5"
print(x + int(y))

12. 
Pythonの公式ドキュメントや多数のライブラリが提供されているリポジトリはどこですか?

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

def add(x, y):
return x + y

def calculate_total(a, b, func=add):
return func(a, b)

print(calculate_total(5, 10))
print(calculate_total(5, 10, lambda x, y: x * y))

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

import json
data = {"scores": {"Math": 90, "Science": 85}}
with open("scores.json", "w") as f:
json.dump(data, f, indent=4)
with open("scores.json", "r") as f:
loaded_data = json.load(f)
print(loaded_data["scores"]["Math"])

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

x = "Python"
x * 3

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

x = 5
y = 10
result = x * y - x + y
print(result)

17. 
Python 3において、print文の変更点として正しいものはどれですか?

18. 
次のコードの中で、「Hello, World!」と出力する関数greetを正しく定義する方法はどれでしょうか?

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

def add(a, b=2):
return a + b

result1 = add(5)
result2 = add(5, 3)

print(result1, result2)

20. 
Pythonにおける「リスト内包表記」として正しい説明はどれですか?

21. 
Pythonの「duck typing」の概念に基づく特徴として正しいものはどれですか?

22. 
Pythonの対話モードで「1から10までの整数を降順で表示する」には、どのようなコードを入力すべきですか?

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

def default_and_keyword(x, y=10, *, z):
return x + y + z

print(default_and_keyword(1, z=5))

24. 
Pythonのファイル拡張子として正しいものはどれですか?

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

def identity(value=100):
return value

print(identity())
print(identity(50))

26. 
Python 3で導入された「f文字列(フォーマット文字列)」を使用した適切な記述方法はどれですか?

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

def increment(number, step=1):
return number + step

print(increment(5))
print(increment(5, 2))

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

import json
data = {"name": "Frank", "age": 28, "is_student": False}
json_string = json.dumps(data, sort_keys=True)
print(json_string)

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

def concatenate(str1, str2=", ", str3="!"):
return str1 + str2 + str3

print(concatenate("Hello"))
print(concatenate("Hello", " World"))
print(concatenate("Hello", " World", "?"))

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

def func(x, y=10):
return x + y

print(func(5))
print(func(5, 15))

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

def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)

print(factorial(3))
print(factorial(5))

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

x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
print(y)

33. 
Pythonの「コメント」を記述する際に使用する記号はどれですか?

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

def multiply(x, y=3, z=2):
return x * y * z

print(multiply(4))
print(multiply(4, 5))
print(multiply(4, 5, 6))

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

try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")

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

import json
data = {"numbers": [10, 20, 30, 40]}
json_data = json.dumps(data, separators=(",", ":"))
print(json_data)

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

import json
json_data = '{"items": [10, 20, 30]}'
data = json.loads(json_data)
print(data["items"][1])

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

try:
result = "text" + 5
except TypeError as e:
print("TypeError occurred:", e)

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

def join_strings(*args):
return ", ".join(args)

print(join_strings("apple", "banana", "cherry"))
print(join_strings("Python", "Java"))

40. 
次のコードで、2つの数値を引数に取り、その合計を返す関数addを正しく定義する方法はどれでしょうか?

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