pytho入门第一天——函数

# # -*-coding:utf-8-*-
##函数部分\
#函数定义:一段可重用的函数段,函数名则是这个函数段的名称
#可在自己的程序中使用这个函数名调用这段函数
#python自带的库中自带了很多基本的函数

#example one
# def Fun_hello():
#     print 'hello world'
# Fun_hello()
##如上函数Fun_hello没有参数

#example two
# def Fun_getMax(a,b):
#     if a>b:
#         print a,'is the maximum'
#     else:
#         print b,'is the maximum'
# Fun_getMax(3,4)
#函数Fun_getMax(a,b)为自定义的函数

##局部变量的使用
# def Fun_part(a):
#     print 'a is ',a
#     a=3;
#     print 'a is changed to ',a
# a=50
# Fun_part(a)
# print 'a still is ',a
##在函数定义内声明变量的时候,他们与函数外具有相同名称的
##变量没有任何关系,即变量名称对于函数来说是局部的,不会
##外部程序的变量产生影响,这称为作用域。所有变量的作用域
##是他们被定义的块,从他们的名称被定义的那个点;

# global x
# def Fun_global(x):
#     print 'the value of x in the fun is ',x
#     x=20
#     print 'x is changed to ',x
# x=50
# Fun_global(x)
# print 'x still is ',x

# def Fun_global():
#     global  x
#     print 'x is ' ,x
#
#     x=2
#     print 'changed local x to ',x
# x=50;
# Fun_global();
# print 'value of x is ',x
##该函数在内部定义x,那么函数内的语句对全局变量的改写
##也涉及到整个函数的x的值的改写








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值