首页 > 编程语言 > 详细

python函数01

时间:2017-12-22 20:29:52      阅读:205      评论:0      收藏:0      [点我收藏+]
# 没有参数和返回的函数
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_strs


repeated_strings = repeat_str("Happy Birthday!", 4)
print(repeated_strings)


# 全局变量与局部 变量
x = 60

def 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!
9
hello China!
hello Python!
Happy Birthday!Happy Birthday!Happy Birthday!Happy Birthday!
x is: 60
change local x to 3
x is still 60

  

python函数01

原文:http://www.cnblogs.com/zlz-leidaxia/p/8087431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!