Chinaunix首页 | 论坛 | 博客
  • 博客访问: 267644
  • 博文数量: 113
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1044
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-15 16:09
文章分类

全部博文(113)

文章存档

2016年(5)

2015年(108)

我的朋友

分类: Python/Ruby

2015-09-04 02:53:03

1.py
函数定义

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. a=100
  3. b=200
  4. def add () :
  5.     c=a+b
  6.     print c
  7. add ()    //调用函数
2.py
实参和形参

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. def add (x,y) :
  3.     c=x+y
  4.     print c
  5. add (100,200)
3.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. def add (x,y) :
  3.     if x==y :
  4.         print x,'=',y
  5.     else :
  6.         print x,'!=',y
  7. s1=raw_input("input something:")
  8. s2=raw_input("input something:")
  9. add (s1,s2)
4.py
支持中文

点击(此处)折叠或打开

  1. #!/usr/bin/python
    #-*- coding: UTF-8 -*-
    def mashine (x,y) :
        print "生成一个", x ,'元', y,'口味的冰激凌'
    mashine(5,'巧克力')
5.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
    #coding: UTF-8
    x=100
    def fun():
    global y
    y=200
    print  x+y
    fun()
    print y
6.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. #coding : utf-8
  3. #quan jubu
  4. x=100
  5. def fun(x,y) :
  6.     if x==y :
  7.         print x ,"=", y
  8.     else :
  9.         print x ,'!=', y
  10. fun(50,50)
7.py
#  return   返回值

点击(此处)折叠或打开

  1. #    return
  2. #!/usr/bin/python
  3. #coding : utf-8
  4. #quan jubu
  5. x=100
  6. def fun(x,y) :
  7.     if x==y :
  8.         print x ,"=", y
  9.         return 0
  10.     else :
  11.         print x ,'!=', y
  12.         return 1


  13. x=fun(50,1000)
  14. print x
8.py   //定义函数,输出字符串

点击(此处)折叠或打开

  1. #    return
  2. #!/usr/bin/python
  3. #coding : utf-8
  4. #quan jubu
  5. t=['name','adustdu']
  6. def fun(x,y) :
  7.     print "%s %s" % ( x , y)
  8.       #注意x,y有括号

  9. fun (t[0],t[1])
  10. #或者用  fun(*t)








阅读(1009) | 评论(0) | 转发(0) |
0

上一篇:python 笔记6 循环结构

下一篇:JAVA学习笔记

给主人留下些什么吧!~~