设为首页 加入收藏

TOP

Python Base Two(一)
2017-09-30 17:14:22 】 浏览:1893
Tags:Python Base Two

//fourth day to study python

24. In python , how to create funcation.

    we can use def to define funcation. such as:

    def MyFirstFuncation():

            print('this is my first funcation')

    MyFirstFuncation()

    -> this is my first funcatio.

    if there are no MyFirstFuncation , it will be have an error.

    of course , we can pass a parameter

    def MySecondFuncation(language):

            print(' i love  ' + language)

    MySecondFuncation('python')

    ->i love python

    if parameter is more , we can use comma divided parameter, such as:

    def AddFuncation(num1,num2):

              print(num1 + num2)

    -> 3

    how to use return:

    def SubFuncation(num1,num2):

              return (num1 - num2)

    print(SubFuncation(6,3))

    -> 3

    ok , next to study

    def myFuncation(m):

         'do you know what is funcation'

          #this is secret

          print('my'+m+'roy')

    myFuncation.__doc__

    -> do you know what is funcation

    next example:

    def sortFuncation(str1,str2):

            print(str1,str2)

    sortFuncation('second','first')

    -> second first

    sortFuncation(str2 = 'second', str1 = 'first')

    -> first second

    default funcation:

    def defaultFuncation(name='wyg',age='12'):

             print(my name is '+name+'age is '+age)

     defaultFuncation()

     -> my name is wyg age is 12

    def textPara(*paras):
           print('parameters length is:',len(paras))
           print('the second parameters is:',paras[1])

    textPara(1,2,3,'roy')
    ->

    parameters length is: 4
    the second parameters is: 2

    def textPara(*paras,exp):
           print('parameters length is:',len(paras),exp)
           print('the second parameters is:',paras[1])

    textPara(1,2,3,'roy',exp = 6)
    ->

    parameters length is: 4 6
    the second parameters is: 2

//fifth day to study python(2016/8/6)

25. In python ,how to retu

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Flask Restful Small Demo 下一篇利用Python进行数据分析(8) panda..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目