โค้ด: เลือกทั้งหมด
total = 0
def mysum(arg1, arg2, arg3):
total = arg1+arg2+arg3
print("ตัวแปรที่เป็น local=", total)
return total
mysum(10,20,30)
print("ตัวแปรที่เป็น global=", total)
ผลลัพธ์
- Selection_025.png (7.91 KiB) Viewed 359 times
โค้ด: เลือกทั้งหมด
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)
ผลลัพธ์
- Selection_026.png (7.17 KiB) Viewed 359 times
โค้ด: เลือกทั้งหมด
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)
ผลลัพธ์
- Selection_027.png (7.8 KiB) Viewed 359 times
โค้ด: เลือกทั้งหมด
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)
ผลลัพธ์
- Selection_028.png (10.18 KiB) Viewed 359 times
โค้ด: เลือกทั้งหมด
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()
ผลลัพธ์
- Selection_029.png (8.71 KiB) Viewed 359 times