28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Parameters

• str -- This is the string to be checked.

• beg -- This is the optional parameter to set start index of the matching boundary.

• end -- This is the optional parameter to set start index of the matching boundary.

Return Value

This method returns true if found matching string otherwise false.

Example

The following example shows the usage of startswith() method.

#!/usr/bin/python

str = "this is string example....wow!!!";

print str.startswith( 'this' );

print str.startswith( 'is', 2, 4 );

print str.startswith( 'this', 2, 4 );

Let us compile and run the above program, this will produce the following result:

True

True

False

strip([chars])

Description

The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the

end of the string (default whitespace characters).

Syntax

Following is the syntax for strip() method:

str.strip([chars]);

Parameters

• chars -- The characters to be removed from beginning or end of the string.

Return Value

This method returns a copy of the string in which all chars have been stripped from the beginning and the end of

the string.

Example

The following example shows the usage of strip() method.

#!/usr/bin/python

str = "0000000this is string example....wow!!!0000000";

print str.strip( '0' );

Let us compile and run the above program, this will produce the following result:

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!