python函數01

來源:互聯網
上載者:User

標籤:div   hang   全域   str   print   傳回值   sum   body   log   

# 沒有參數和返回的函數def say_hi():    print(" hi!")say_hi()say_hi()# 有參數,無傳回值def print_sum_two(a, b):    c = a + b    print(c)print_sum_two(3, 6)def hello_some(str):    print("hello " + str + "!")hello_some("China")hello_some("Python")# 有參數,有傳回值def repeat_str(str, times):    repeated_strs = str * times    return repeated_strsrepeated_strings = repeat_str("Happy Birthday!", 4)print(repeated_strings)# 全域變數與局部 變數x = 60def foo(x):    print("x is: " + str(x))    x = 3    print("change local x to " + str(x))foo(x)print(‘x is still‘, str(x))

  輸出:

 hi! hi!9hello China!hello Python!Happy Birthday!Happy Birthday!Happy Birthday!Happy Birthday!x is: 60change local x to 3x is still 60

  

python函數01

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.