Descriptionスライス[]を使って文字列の個々の文字にアクセスする方法を見ました。同様に、文字列の特定の部分(連続した複数の文字)を選択することも可能です。これは、同じ[]の中に開始位置と終了位置の2つの数値を指定することで行えます。s = 'This is a long long string' print(s[0: 1]) # T print(s[0: 2]) # Th print(s[0: 18]) # This is a long lon print(s[1: 3]) # hi print(s[1: -1]) # his is a long long strin print(s[3: -2]) # s is a long long stri print(s[-10: -2]) # ong stri注意1: 開始位置は常に含まれ、終了位置は含まれません ⇒ [start; end)。注意2: 開始位置と終了位置の両方に負の値を指定できます(負のインデックスを意味します)。チャレンジ文字列の中央の部分を知りたいとします。長さnの文字列が与えられたとき、位置n/4から3n/4までの文字を表示したいです。入力は1行のテキストで、その長さは4で割り切れることが保証されています。プログラムは中央の部分を出力してください。入力出力abcdbcabcdefghcdefConstraintsTime limit: 1.6 secondsMemory limit: 512 MBOutput limit: 1 MBTo check your solution you need to sign inSign in to continueSign in to your accountSign in with GoogleSign in with FacebookSign in with MicrosoftSign in with emailBy continuing, you agree to our Terms of Service and Privacy Policy.