tests whether an object is a class string
Task
Sometimes it is necessary to test an object, especially if you are writing a function or method, you often need to test whether the passed argument is a string.
Solution Solutions
Use the built-in isinstance and basestring to quickly and easily query whether an object is a string or a Unicode object method, as follows:
Code:
def isastring (AAA): return isinstance (aaa,basestring)
Operation Result:
>>> isastring ('aaa') True
string Alignment
Task
Implement string alignment: Left-justified, centered, right-aligned
Solution Solutions
This is the problem that the Ljust, Rjust, and center methods of the string object solve. Each method requires a parameter that indicates the width of the resulting string, and then returns a copy of the string with spaces added to the left, right, or both ends:
>>>Print "python". Ljust (15,"+") Python+++++++++>>>Print "python". Rjust (15,"+")+++++++++python>>>Print "python". Center (15,"+")+++++python++++