หน้า 1 จากทั้งหมด 2

Re: ทำความรู้จักกับภาษา python (20) : การ return (รีเทิน) ค่าออกจากฟังก์ชัน

โพสต์แล้ว: 10/08/2018 3:51 pm
โดย anuwat somsakul
การสร้างฟังก์ชั่น ส่งค่าออกจากฟังก์ชั่นไพทอน 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
Selection_012.png (12.93 KiB) Viewed 905 times

Re: ทำความรู้จักกับภาษา python (20) : การ return (รีเทิน) ค่าออกจากฟังก์ชัน

โพสต์แล้ว: 10/06/2019 5:40 pm
โดย chatee supasand
อธิบายดีมากครับ

Re: ทำความรู้จักกับภาษา python (20) : การ return (รีเทิน) ค่าออกจากฟังก์ชัน

โพสต์แล้ว: 20/06/2019 4:21 pm
โดย jirawoot

โค้ด: เลือกทั้งหมด

def myfunc(a1,a2):
    total = a1+a2
    print ("ตัวแปรภายในฟังก์ชั่น",total)
    return total

total = myfunc(10,20)
print ("ตัวแปรนอกฟังก์ชั่น ",total)
ผลลัพธ์
Selection_022.png
Selection_022.png (10.15 KiB) Viewed 504 times

Re: ทำความรู้จักกับภาษา python (20) : การ return (รีเทิน) ค่าออกจากฟังก์ชัน

โพสต์แล้ว: 08/06/2020 7:21 pm
โดย MBMoo

โค้ด: เลือกทั้งหมด

def bo(b1,b2):
    bo = b1 +b2
    print ("ออก1",bo)
    return bo

bow = bo(2,3)
print("ออก2",bow)
ผลลัพธ์
Python Knowledge-1.png
Python Knowledge-1.png (1.3 KiB) Viewed 386 times