Pythonで文字列から特定の文字列や空白を削除する方法(strip)です
strip 先頭と末尾のtを削除する
1 2 3 | # strip 先頭と末尾のtを削除する str = "test" .strip( "t" ) print ( str ) |
lstrip 先頭のtを削除する
1 2 3 | # lstrip 先頭のtを削除する str = "test" .lstrip( "t" ) print ( str ) |
rstrip 末尾のtを削除する
1 2 3 | # rstrip 末尾のtを削除する str = "test" .rstrip( "t" ) print ( str ) |
strip 先頭と末尾の空白と改行を削除する
1 2 3 | # strip 先頭と末尾の空白と改行を削除する str = " \ntest test\n " .strip() print ( str ) |
lstrip 先頭の空白と改行を削除する
1 2 3 | # lstrip 先頭の空白と改行を削除する str = " \ntest test\n " .lstrip() print ( str ) |
rstrip 末尾の空白と改行を削除する
1 2 3 | # rstrip 末尾の空白と改行を削除する str = " \ntest test\n " .rstrip() print ( str ) |