LoginSignup
0
0

More than 1 year has 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