Python 11th day Job

Source: Internet
Author: User

#, 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.