Python 3エンジニア認定基礎試験-リスト操作(リストの要素)- 2024年11月13日 ailearn 1. 次のコードの出力は何でしょうか? data = [1, 2, 3, 4, 5]data[::2] = [10, 20, 30]print(data) [10, 2, 20, 4, 30] [1, 2, 3, 4, 5] [10, 20, 30, 4, 5] Error None 2. 次のコードの出力は何ですか? nums = [10, 20, 30, 40, 50]print(nums[-2]) 40 30 50 IndexError None 3. 次のコードの出力は何ですか? data = [10, 20, 30, 40]result = [data[i] + data[i+1] for i in range(len(data)-1)]print(result) [10, 20, 30] [30, 50, 70] [30, 40, 50] Error None 4. 次のコードの出力は何ですか? words = ["apple", "banana", "cherry"]result = [word[0].upper() + word[1:] for word in words]print(result) ['APPLE', 'BANANA', 'CHERRY'] ['apple', 'banana', 'cherry'] ['Apple', 'Banana', 'Cherry'] ['A', 'B', 'C'] None 5. 次のコードの出力は何ですか? data = [5, 3, 9, 1]data.sort(reverse=True)print(data) [5, 3, 9, 1] [9, 5, 3, 1] [1, 3, 5, 9] [1, 9, 5, 3] None 6. 次のコードの出力は何ですか? nums = [10, 20, 30, 40]nums[1:3] = [100]print(nums) [10, 100, 30, 40] [10, 20, 100, 30, 40] Error [10, 100, 40] None 7. 次のコードの出力は何でしょうか? nums = [1, 2, 3, 4, 5]nums[1:4] = []print(nums) [1, 2, 3, 4, 5] [1, 5] [1, 2, 4, 5] Error None 8. リストitems = ["pen", "pencil", "eraser", "sharpener"]の長さを取得するコードはどれでしょうか? length(items) items.length() items.size() len(items) None 9. 次のコードの出力は何でしょうか? lst = [1, [2, 3], [4, [5, 6]], 7]print(lst[2][1][1]) 4 5 6 Error None 10. リストnumbers = [1, 2, 3, 4, 5]のすべての要素を取得するにはどうすればよいでしょうか? numbers[1:5] numbers[:] numbers[0:4] numbers[1:] None 11. 次のコードの出力は何ですか? values = [1, 2, 3, 4, 5]new_values = [val for val in values if val > 3]print(new_values) [4, 5] [1, 2, 3] [1, 2, 3, 4, 5] [3, 4, 5] None 12. 次のコードの出力は何でしょうか? nums = [1, 2, 3, 4, 5]nums[1:4] = [10, 20]print(nums) [1, 10, 20, 5] [1, 10, 20, 4, 5] [1, 10, 20, 3, 4, 5] Error None 13. 次のコードの出力は何でしょうか? fruits = ["apple", "banana", "cherry"]print(fruits[1]) apple banana cherry IndexError None 14. 次のコードの出力は何でしょうか? nums = [1, 2, 3, 4, 5]result = [x**2 for x in nums if x % 2 == 0]print(result) [4, 16] [1, 4, 9, 16, 25] [1, 9, 25] [2, 4] None 15. 次のコードの出力は何でしょうか? numbers = [5, 10, 15, 20, 25]numbers[0:3] = [1, 2]print(numbers) [1, 2, 5, 10, 15, 20, 25] [5, 10, 15, 1, 2, 20, 25] [1, 2, 15, 20, 25] [1, 2, 20, 25] None 16. 次のコードの出力は何でしょうか? animals = ["cat", "dog", "elephant"]animals[1] = "fox"print(animals) ["cat", "dog", "elephant"] ["fox", "dog", "elephant"] ["cat", "fox", "elephant"] ["cat", "dog", "fox"] None 17. 次のコードの出力は何でしょうか? values = [1, 2, 3, 4, 5]values[2] = 10print(values) [1, 2, 3, 4, 5] [10, 2, 3, 4, 5] [1, 10, 3, 4, 5] [1, 2, 10, 4, 5] None 18. 次のコードの出力は何ですか? data = [1, 2, 3, 4]result = [x + y for x in data for y in data if x != y]print(result) [3, 4, 5, 5, 6, 7, 5, 6, 7, 6, 7, 8] [3, 4, 5, 3, 5, 6, 4, 5, 7, 5, 7, 6] [4, 3, 5, 5, 6, 7, 5, 6, 7, 6, 7, 8] [3, 4, 5, 3, 5, 6, 4, 5, 7, 5, 6, 7] None 19. 次のコードの出力は何ですか? letters = ['a', 'b', 'c', 'd', 'e']print(letters[1:4]) ['a', 'b', 'c', 'd'] ['b', 'c', 'd'] ['b', 'c', 'd', 'e'] ['c', 'd', 'e'] None 20. 次のコードの出力は何でしょうか? numbers = [1, 2, 3, 4, 5, 6]numbers[1:5:2] = [7, 8]print(numbers) [1, 7, 8, 4, 5, 6] [1, 7, 3, 4, 5, 6] Error [1, 7, 3, 8, 5, 6] None Time's up