Passing a parameter - Function: If it is purely digital, then return: This is a string of numbers, if it is English or English plus a number, put all the English converted to uppercase
The first method: Custom
def lowerToUpper(s): d = {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G' } # Dictionary not write the whole IF s.isdigit () == True: return ' This is a purely digital string ' newS = "" # If parameters are passed in English, and numbers for item in S: # of the item for Analyzing (item is in each element s) IF item.isdigit () == True: newS + = Item elif item.isalpha () == True: IF Item in D == False: newS + = Item the else : newS += d[item] return newS s = 'asdfasdfasdf' print(s.upper())
Operating results as follows:
ASDFASDFASDF
The second method: using built-in functions
DEF lowertoupper (s): IF s.isdigit () == True: Print ( " It is a pure digital string " ) News = "" # of item1 judgment (item is in each element s) for item1 in s : #for circulation in the print statement can be removed, just to see me more clearly iF item1.isdigit () == True: # determine whether the digital elements News + = ITEM1 print ( " this is a digital {} " . format (ITEM1)) # format to format elif item1.islower () == True: # determine whether the element is lowercase, then uppercase letters + = News item1.upper () Print ( " It is a lowercase} { " .format (ITEM1)) the else : Print ( " It is a capital letter} { " .format (ITEM1)) News + = ITEM1 return News Print (lowertoupper ( " 1235aAhfkdshfk " ))
Results are as follows:
This is a digital 1
it is a number 2
which is a number 3
which is a number 5
which is a lower case letter a
This is a capital letter A
which is a lower case letter h
which is a lowercase f
which is a lowercase k
this is a lowercase d
this is a lowercase s
which is a lower case letter h
which is a lowercase f
which is a lowercase K
1235AAHFKDSHFK