LeftPad in Python
def leftPad(inputStr, paddedLength, ch='.'):if len(ch) != 1:raise Exception('Invalid Input')paddedLength = paddedLength - len(inputStr)return ch * paddedLength + inputStrprint leftPad('1', 1)print leftPad('2', 2)print leftPad('3', 3)print leftPad('4', 4)print leftPad('5', 5)print leftPad('hello', 7)print leftPad("foo", 6)print leftPad("foo", 3)print leftPad("foobar", 3)print leftPad("foo", 6, "?")