แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน
Moderator: mindphp , ผู้ดูแลกระดาน
anuwat somsakul
PHP Full Member
โพสต์: 44 ลงทะเบียนเมื่อ: 08/08/2018 9:49 am
โพสต์ที่ยังไม่ได้อ่าน
โดย anuwat somsakul » 10/08/2018 3:51 pm
การสร้างฟังก์ชั่น ส่งค่าออกจากฟังก์ชั่นไพทอน The return Statement:
โค้ด: เลือกทั้งหมด
total = 10
def myfucn1(arg1,arg2):
a = 15
total = arg1 + arg2
print("ตัวแปรภายในฟังก์ชัน :",a)
print("ตัวแปร total ที่อยู่ภายในฟังก์ชัน :", total)
return total
total = myfucn1(10,20)
print("ตัวแปร total ที่อยู่ภายนอกฟังก์ชัน :",total)
ผลลัพธ์
Selection_012.png (12.93 KiB) Viewed 864 times
jirawoot
PHP VIP Members
โพสต์: 3129 ลงทะเบียนเมื่อ: 17/06/2019 10:30 am
โพสต์ที่ยังไม่ได้อ่าน
โดย jirawoot » 20/06/2019 4:21 pm
โค้ด: เลือกทั้งหมด
def myfunc(a1,a2):
total = a1+a2
print ("ตัวแปรภายในฟังก์ชั่น",total)
return total
total = myfunc(10,20)
print ("ตัวแปรนอกฟังก์ชั่น ",total)
ผลลัพธ์
Selection_022.png (10.15 KiB) Viewed 493 times
MBMoo
PHP VIP Members
โพสต์: 25341 ลงทะเบียนเมื่อ: 04/06/2020 10:05 am
โพสต์ที่ยังไม่ได้อ่าน
โดย MBMoo » 08/06/2020 7:21 pm
โค้ด: เลือกทั้งหมด
def bo(b1,b2):
bo = b1 +b2
print ("ออก1",bo)
return bo
bow = bo(2,3)
print("ออก2",bow)
ผลลัพธ์
Python Knowledge-1.png (1.3 KiB) Viewed 375 times
0 ตอบกลับ
1419 แสดง
โพสต์ล่าสุด โดย tatiya
16/08/2018 4:36 pm
0 ตอบกลับ
1299 แสดง
โพสต์ล่าสุด โดย ธวัชชัย แสนหาญ
14/02/2019 6:05 pm
5 ตอบกลับ
1674 แสดง
โพสต์ล่าสุด โดย MBMoo
13/06/2020 10:34 am
0 ตอบกลับ
4281 แสดง
โพสต์ล่าสุด โดย Jom07
06/03/2018 3:17 pm
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 32