ezoic

Thursday, February 16, 2017

Python bool function and a python program

bool function will return false or true for a statement.

And we can apply arithmetic operations on it. Here are some examples.



Here is one example, testing a string is palindrome or not:


class Solution:
    def is_palindrome(self, x1):
        bool1=1
        list1=list(x1)
        for i in range(int(len(list1)/2)):
             bool1=bool(list1[i]==list1[len(list1)-1-i])*bool1

        if bool1==1:
            return('True')
        else:
            return('False')


kk=Solution()
print(kk.is_palindrome('aba'))

Results:

True



No comments:

Post a Comment

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...