简体   繁体   中英

Python skip first line of multiline string

Is there a way to skip the first line of a multiline string? So that I can do this:

str = """
  some
  indented
  stuff"""

instead of

str = """  some
  indented
  stuff"""

The python parser takes any end-of-line \ in the code followed by no characters as a line break for the parser :

x = """\
  some
  indented
  stuff"""
str = """ some indented stuff""" def formatter(my_str): return '\n'.join([elem.strip() for elem in my_str.split('\n')[1:]]) print(formatter(str))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM