0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Split string with \n in python

Posted at
  • source
import sys

sa = sys.argv[1]
l = sa.split("\\n") # not \n
print(l)
if len(l) >= 2:
    ret = float(l[len(l)-1])
else:
    ret = float(sa)
print(ret)
  • execution
# python3 test.py "3.1"
['3.1']
3.1
# python3 test.py "3.1\n3.2"
['3.1', '3.2']
3.2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?