zoukankan      html  css  js  c++  java
  • day-3 函数

     1 def write_file(filename,content):#filename,content都是形式参数
     2     with open(filename,'a+',encoding='utf-8') as fw:
     3         fw.write(content+'
    ')
     4 
     5 
     6 def read_file(filename):
     7     with open(filename,encoding='utf-8') as fr:
     8         result = fr.read()
     9         return result#返回值,什么时候需要返回值,要看具体函数的作用
    10     #函数里面遇到return,函数立即结束
    11 
    12 write_file('a.txt','aaaaaa')
    13 rea = read_file('a.txt')#a.txt是实际参数
    14 print(rea)
    15 
    16 def more():
    17     name = 'xiaoming'
    18     age = 18
    19     score = 99
    20     return name,age,score
    21 #多个返回值
    22 # 方法1
    23 result = more()
    24 print(result)
    25 # 方法2
    26 name,age,score = more()# 用3个值来接收
    27 print(name)
    28 print(age)
    29 print(score)
    30 
    31 # 默认值参数
    32 def user(name,sex=''):
    33     print(name,sex)
    34 user('xiaobai','')
    35 user('xiaolan')
  • 相关阅读:
    CSS属性之定位
    CSS选择器区别
    HTML属性及其相关区别
    HTML标签区别
    HTML其他概念
    CSS3新特性
    HTML5新标签
    HTML5新特性
    params修饰符的用法
    C#中引用参数ref和输出参数out
  • 原文地址:https://www.cnblogs.com/hujc/p/11747954.html
Copyright © 2011-2022 走看看