ทำความรู้จักกับภาษา python (21) : ขอบเขตของตัวแปรฟังก์ชัน
Moderator: mindphp, ผู้ดูแลกระดาน
- chatee supasand
- PHP VIP Members
- โพสต์: 1666
- ลงทะเบียนเมื่อ: 04/06/2019 10:06 am
Re: ทำความรู้จักกับภาษา python (21) : ขอบเขตของตัวแปรฟังก์ชัน
สอนดีเวรี่กู้ดมากครับ
- jirawoot
- PHP VIP Members
- โพสต์: 3129
- ลงทะเบียนเมื่อ: 17/06/2019 10:30 am
Re: ทำความรู้จักกับภาษา python (21) : ขอบเขตของตัวแปรฟังก์ชัน
โค้ด: เลือกทั้งหมด
total = 0
def mysum(arg1, arg2, arg3):
total = arg1+arg2+arg3
print("ตัวแปรที่เป็น local=", total)
return total
mysum(10,20,30)
print("ตัวแปรที่เป็น global=", total)
โค้ด: เลือกทั้งหมด
total = 0
def mysum(arg1, arg2, arg3):
total = arg1+arg2+arg3
print("ตัวแปรที่เป็น local=", total)
return total
total=30
mysum(10,20,30)
print("ตัวแปรที่เป็น global=", total)
โค้ด: เลือกทั้งหมด
def myfunc(a,b):
a=10
print('ตัวแปร a =',a)
print('ตัวแปร b =', b)
a=20
b=30
print('global a=',a)
print('global b=',b)
print('----------------')
myfunc(a,b)
โค้ด: เลือกทั้งหมด
def myfunc2(c, d):
print('เรียกใช้ฟังก์ชั้นที่ 2')
return (c+d)
a=20
b=30
print('global a =',a)
print('globla b =',b)
print('----------------')
total= myfunc2(a, b)
print('local a+b=', total)
โค้ด: เลือกทั้งหมด
def myfunc3():
a = 0
b = 1
print('เรียกฟังก์ชั่นที่ 3')
print("local a=",a)
print('local b=', b)
a= 20
b=30
print('global a=',a)
print('globle b=',b)
print('---------------')
myfunc3()
-
- Similar Topics
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
-
โพสต์ใหม่ การใช้งาน Python GUI (Tkinter) : การเรียกใช้ from ใน python 2 และ python 3
โดย Jom07 » 06/03/2018 3:17 pm » ใน Python Knowledge - 0 ตอบกลับ
- 4463 แสดง
-
โพสต์ล่าสุด โดย Jom07
06/03/2018 3:17 pm
-
-
-
โพสต์ใหม่ แนะนำเวอร์ชัน Python ในปัจจุบัน Python 3.10 หรือ Python 3.11
โดย athirach.offcial » 29/03/2024 3:20 pm » ใน Python Knowledge - 0 ตอบกลับ
- 843 แสดง
-
โพสต์ล่าสุด โดย athirach.offcial
29/03/2024 3:20 pm
-
-
-
โพสต์ใหม่ ทำความรู้จักกับภาษา python (23) : การใช้ from...import (ฟอร์ม...อิมพอร์ต) ในภาษา python (ไพทอน)
โดย dawthana » 12/01/2017 3:24 pm » ใน Python Knowledge - 9 ตอบกลับ
- 6648 แสดง
-
โพสต์ล่าสุด โดย jirawoot
21/06/2019 10:07 am
-
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 94