#, write the function, calculate the number of "number", "Letter", "space" and "other" in the incoming string
def count (s):
Nu,st,sp,it = 0,0,0,0
For I in S:
If I.isdigit ():
Nu + = 1
Elif I.isalpha ():
St + + 1
Elif I.isspace ():
SP + = 1
Else:it + = 1
Print (' \ n ' in string%s has a \033[45m%s\033[0m \n\
The letter has \033[44m%s\033[0m a \ n space \033[45m%s\033[0m a \n\
Others have \033[45m%s\033[0m \ n '% (s,nu,st,sp,it))
s = input (' Please enter string: ')
Count (s)
#写函数 to determine whether the length of the object passed in by the user (string, list, tuple) is greater than 5
def cmlen (*args):
Print (args)
For i in args:
If Len (i) > 5:print (i, ' length greater than 5 ')
Else:print (i, ' length less than or equal to 5 ')
L = [1,2,3,4,5,6,7,8,9,0]
m = (1,2,3,4)
s = ' DFXFFDFDGDSFDSF '
Cmlen (L,m,s)
#写函数, the length of the incoming list is checked, if it is greater than 2, only the first two length of content is retained, and the new content is returned to the caller
def listcut (L):
If Type (l) is list:
If Len (l) >2:
return L[:2]
Else:return L
Else:print (' parameter error, should pass in list ')
L = [1]
Print (Listcut (l))
#写函数, checks for the element corresponding to all the odd-bit indexes of the passed-in list or tuple object and returns it to the caller as a new list
def checklist (L):
if (Type (l) is a list or type (l) is a tuple) and Len (l)! = 0:
Return list (L[1::2])
Else:print (' Please enter a list or tuple with at least two elements ')
L = [+]
Print (Checklist (L))
Python 11th day Job