Section 25th, Custom function jobs

Source: Internet
Author: User

1, the differences between common parameters, specified parameters, default parameters and dynamic parameters are briefly described.

Function

A.def (declare custom function Start)

B. function name () such as: F1 ()

C. Returned value return (keyword)

Once a return is encountered inside the function, the following code is not executing

D. Parameters

1. Formal parameters (parameters when defining a function), actual parameters (parameters when the function is called)

2. Common parameters: The same quantity, each corresponding

Print (" Common parameters: Consistent quantity, each corresponding ") def F1 (A, b    ): = A + b    print(c) F1 (5,5)

3. Specifying parameters

Specify parameters when calling a function such as: F1 (p= "xxx")

Print (" Specify parameters: Specify parameters when calling a function ") def G1 (A, b    ): = A + b    print= 4, a = 3)

4. Default parameters

The formal parameter specifies the default argument when the function is defined, and the default parameter is written in the trailer

Print (" default parameter: Formal parameter specifying default argument when defining a function ") def H1 (a=5, b=3):    = a + b    print(c) H1 ()

5. Dynamic Parameters

*args (receive actual parameter combination Narimoto group)

Print (" dynamic parameter: *args (receive actual parameter combination Narimoto group)") def i1 (*args):    print(args) i1 (123, 456, 789)

**kwargs (receive actual parameters combined into a dictionary)

Print (" Dynamic Parameters: **kwargs (receive actual parameters combined into a dictionary)") def J1 (* *Kwargs)    :print(kwargs) J1 (K1=123,k2=456,k3=789)

2, write the function, calculate the number of "number", "Letter", "space" and "other" in the incoming string

#!/usr/bin/env python#-*-coding:utf-8-*-#Write a function that calculates the number of "number", "Letter", "Space", and "other" in the passed-in stringdefPduan (s): Shuzi= 0#Statistical figuresZimu = 0#Statistical AlphabetKongge = 0#Statistics SpaceQita = 0#Statistics Other     forIinchS#Looping Strings        ifI.isdigit ():#determines whether the character being looped is a numberShuzi + = 1#if it's a number, the statistics plus 1        elifI.isalpha ():#determines whether the character being looped is a letterZimu + = 1#if it's a letter, Count plus 1.        elifI.isspace ():#determines whether the loop-through character is a spaceKongge + = 1#if it is a space, statistics plus 1        Else:#determines whether the character that is looped to is not the above type;Qita + = 1#if it is other, the other statistics plus 1    return{"Shuzi": Shuzi,"Zimu": Zimu,"Kongge": Kongge,"Qita": Qita}#returns a dictionary of combinations of various statisticsJieg= Pduan ("1567df Jweiwo r22r")#calling a function to pass in a stringPrint(Jieg)#Print functionPrint("\ n")#The number of each statistic to be obtained by means of a dictionary indexPrint("Number:", jieg["Shuzi"],"Letters:", jieg["Zimu"],"Space:", jieg["Kongge"],"Other:", jieg["Qita"])

3, write function, determine whether the user incoming object (string, list, tuple) length is greater than 5

Section 25th, Custom function jobs

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.