python笔记:1.5函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bq_cui/article/details/90040844
# -*- coding: utf-8 -*-
"""
Created on Thu May  9 16:13:23 2019

@author: Administrator
"""



def snn(n, beg = 1):
    '计算1到n的自然数之和。'
    s = 0
    i = 0
    while i <= n:
        s += i
        i += 1
        
    return s    

print(snn(100))

f = snn # 函数赋值给变量对象

print(f(50))
    

运行:

5050
1275

猜你喜欢

转载自blog.csdn.net/bq_cui/article/details/90040844