zoukankan      html  css  js  c++  java
  • python

    # -*- coding:utf-8 -*-

    '''
    @project: jiaxy
    @author: Jimmy
    @file: study_函数的相互调用及变量的作用域.py
    @ide: PyCharm Community Edition
    @time: 2018-11-10 10:04
    @blog: https://www.cnblogs.com/gotesting/

    '''


    # 1. 函数的相互调用
    # 从上往下按顺序执行

    def print_msg(content):
    print('我想说:{}'.format(content))


    def learn_language(name,content):
    print('我正在学{}语言'.format(name))
    print_msg(content)


    learn_language('python','so easy')



    # 2. 变量的作用域
    # 全局变量 & 局部变量

    '''
    (1)如果函数内部没有这个变量,使用全局变量
    (2)当全局变量与局部变量重名的时候,函数内容优先使用自己的局部变量
    (3)如果在函数内部声明了全局变量,我们可以在函数内部改变全局变量的值,全局生效
    '''

    a = 5 #全局变量,作用域本模块

    def add(b):
    global a # 声明他是全局变量
    a = 6 # 局部变量,只能作用于该函数内部
    print(a+b)

    def sub(b):
    print(a-b)

    add(10)
    sub(5)
    print(a)
  • 相关阅读:
    Git`s Operation
    从volatile说到,i++原子操作,线程安全问题
    sql中的几种删除方式
    Hibernate&MyBatis different
    集合问答
    Data Struct and Data Type
    Hash table and application in java
    idea`s shortcut key
    001--idea第一个报错JNI报错
    recyclebin
  • 原文地址:https://www.cnblogs.com/gotesting/p/9938547.html
Copyright © 2011-2022 走看看