曖昧な日付形式
「In the face of ambiguity, refuse the temptation to guess.」の観点から、01/02/2026 のような日付の文字列を読み取る処理の書き方として、最も適切なものを1つ選べ。
- A
日付の形式(月/日/年か、日/月/年か)を、
formatで明示して変換する。 - B
形式を指定せず、自動の判定に任せる。
- C
すべてのデータを、月/日/年だと決めつけて、確認しない。
- D
日付の列は、使わずに捨てる。
正解と解説を見る
正解:A
曖昧な入力は、推測ではなく、形式を明示して扱う。datetime.strptime や pd.to_datetime(format=...) で、形式を指定する。
| 格言 | 意味 |
|---|---|
| Beautiful is better than ugly. | 美しい方が、醜いよりよい |
| Explicit is better than implicit. | 明示的な方が、暗黙的よりよい |
| Simple is better than complex. | 単純な方が、複雑よりよい |
| Complex is better than complicated. | 複雑でも、ごちゃごちゃ(complicated)よりはよい |
| Flat is better than nested. | 平らな方が、入れ子より(深い入れ子より)よい |
| Sparse is better than dense. | ゆとりのある方が、詰め込みよりよい |
| Readability counts. | 読みやすさは大事 |
| Special cases aren't special enough to break the rules. | 特別な場合でも、規則を破るほど特別ではない |
| Although practicality beats purity. | ただし、実用性は純粋さに勝る |
| Errors should never pass silently. | エラーを黙って見過ごしてはいけない |
| Unless explicitly silenced. | 明示的に黙らせた場合は別 |
| In the face of ambiguity, refuse the temptation to guess. | あいまいなときは、推測したくなる誘惑を断る |
| There should be one-- and preferably only one --obvious way to do it. | 明白なやり方が1つ、できればただ1つだけあるべき |
| Although that way may not be obvious at first unless you're Dutch. | その方法は、オランダ人でなければ最初は分かりにくいかもしれない |
| Now is better than never. | やらないよりは、今やる方がよい |
| Although never is often better than *right* now. | ただし、「今すぐ」よりやらない方がよいことも多い |
| If the implementation is hard to explain, it's a bad idea. | 実装を説明しにくいなら、悪い考え |
| If the implementation is easy to explain, it may be a good idea. | 実装を説明しやすいなら、よい考えかもしれない |
| Namespaces are one honking great idea -- let's do more of those! | 名前空間は素晴らしい考え。もっと活用しよう |
- A
正しい。推測に任せると、月と日を取り違える。
- B
誤り。曖昧なので、取り違える可能性がある。
- C
誤り。推測で処理している。
- D
誤り。情報を失う。
このサイトの問題は、各試験の公式に示された出題範囲に沿って作ったオリジナルの模擬問題です。本試験の問題ではありません。一般社団法人Pythonエンジニア育成推進協会の公式サービスではありません。