コンテンツへスキップ

blog.PanicBlanket.com

takatoh's blog – Learning programming languages.

  • ホーム
  • ブログ

日: 2014年6月5日

Pythonで改行文字を取り去るにはstrip()でOK

今日気がついたんだけど、タイトルのとおり。

>>> "foobarbaz\n".strip()
'foobarbaz'

今まで strip() は空白文字を取り去るもんだと思い込んでて、改行文字を取るにはこう書いてたよ…orz。

>>> "foobarbaz\n".rstrip("\n")
'foobarbaz'
投稿者 takatoh投稿日: 2014年6月5日2014年6月7日カテゴリー PythonPythonで改行文字を取り去るにはstrip()でOKにコメント
2014年6月
日 月 火 水 木 金 土
1234567
891011121314
15161718192021
22232425262728
2930  
« 5月   7月 »

アーカイブ

  • AIR
  • algorithm
  • bouldering
  • C
  • CentOS
  • Clojure
  • Cpp
  • Elixir
  • Go
  • Haskell
  • Java
  • JavaScript
  • Linux Mint
  • Mac
  • misc
  • OCaml
  • Perl
  • PHP
  • Python
  • RockyLinux
  • Ruby
  • Scala
  • Scheme
  • Ubuntu
  • Windows

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
  • ホーム
  • ブログ
blog.PanicBlanket.com Proudly powered by WordPress