Tuesday, July 20, 2021

Program on String Functions.


Understanding string functions. 

 

isalnum() - returns True if character is alphabet or number.

in a string, returns True if string contains only letters and alphabets.

                    returns False if string contains special characters.

                    string="abg1234".isalnum()    #returns True

                    string="abg12@#$34".isalnum()    #returns False

isalpha() - returns True if character is an alphabet.

isdigit() - returns True if character is a number.

islower() - returns True if character is a lower case alphabet.

isupper() - returns True if character is a upper case alphabet.

 

Input Format

A single line containing a string 

Output Format

In the first line, print True if string has any alphanumeric characters. Otherwise, print False.

In the second line, print True if string has any alphabetical characters. Otherwise, print False.

In the third line, print True if string has any digits.Otherwise, print False.

In the fourth line, print True if string has any lowercase characters. Otherwise, print False.

In the fifth line, print True if string has any uppercase characters. Otherwise, print False

 

Sample Input:

qA2

Sample Output:

True

True

True

True

True

 

Solution:

if __name__ == '__main__':
    s = input()
    r1=False
    r2=False
    r3=False
    r4=False
    r5=False
    for i in range(0,len(s)):
        if(s[i].isalnum()):
            r1=True
        if(s[i].isalpha())and(s[i].islower()):
            r2=True
            r4=True
        elif(s[i].isalpha())and(s[i].isupper()):
            r2=True
            r5=True
        elif(s[i].isnumeric()):
            r3=True
    print(r1)
    print(r2)
    print(r3)
    print(r4)
    print(r5)
 

 

No comments:

Post a Comment

Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...