28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

trantab = maketrans(intab, outtab)

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

print str.translate(trantab);

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

th3s 3s str3ng 2x1mpl2....w4w!!!

Following is the example to delete 'x' and 'm' characters from the string:

#!/usr/bin/python

from string import maketrans

# Required to call maketrans function.

intab = "aeiou"

outtab = "12345"

trantab = maketrans(intab, outtab)

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

print str.translate(trantab, 'xm');

This will produce following result:

th3s 3s str3ng 21pl2....w4w!!!

upper()

Description

The method upper() returns a copy of the string in which all case-based characters have been uppercased.

Syntax

Following is the syntax for upper() method:

str.upper()

Parameters

• NA

Return Value

This method returns a copy of the string in which all case-based characters have been uppercased.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!