Skip to main content
Update link to docs, PEP8 and formatting
Source Link
user3064538
user3064538

As pointed out in answers above

myStringmy_string.strip() 

will remove all the leading and trailing whitespace characters such as \n\n, \r\r, \t\t, \f\f, space .

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()my_string.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()my_string.rstrip()
  • Removes specific whitespace chars: myStringmy_string.strip('\n') or myStringmy_string.lstrip('\n\r') or myStringmy_string.rstrip('\n\t') and so on.

More details are available in the docsdocs.

As pointed out in answers above

myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()
  • Removes specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

More details are available in the docs

As pointed out in answers above

my_string.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space .

For more flexibility use the following

  • Removes only leading whitespace chars: my_string.lstrip()
  • Removes only trailing whitespace chars: my_string.rstrip()
  • Removes specific whitespace chars: my_string.strip('\n') or my_string.lstrip('\n\r') or my_string.rstrip('\n\t') and so on.

More details are available in the docs.

deleted 1 character in body
Source Link
alex
  • 492.2k
  • 205
  • 890
  • 992

As pointed out in answers above

 myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()
  • Removes specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

More details are available in the docs

As pointed out in answers above

 myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()
  • Removes specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

More details are available in the docs

As pointed out in answers above

myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()
  • Removes specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

More details are available in the docs

Shortened sentences, changed url to link
Source Link

As pointed out in answers above

 myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removal ofRemoves only leading whitespace chars: myString.lstrip()
  • Removal ofRemoves only trailing whitespace chars: myString.rstrip()
  • Removal ofRemoves specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

TheseMore details are also available atin the http://docs.python.org/release/2.3/lib/module-string.html

As pointed out in answers above

 myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removal of only leading whitespace chars: myString.lstrip()
  • Removal of only trailing whitespace chars: myString.rstrip()
  • Removal of specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

These details are also available at http://docs.python.org/release/2.3/lib/module-string.html

As pointed out in answers above

 myString.strip() 

will remove all the leading and trailing whitespace characters such as \n, \r, \t, \f, space.

For more flexibility use the following

  • Removes only leading whitespace chars: myString.lstrip()
  • Removes only trailing whitespace chars: myString.rstrip()
  • Removes specific whitespace chars: myString.strip('\n') or myString.lstrip('\n\r') or myString.rstrip('\n\t') and so on.

More details are available in the docs

Source Link
Mudit Jain
  • 4.2k
  • 2
  • 24
  • 20
Loading