ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย jirawoot » 20/06/2019 12:09 pm

true

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

var_int = 10
if var_int == 10:
    print ("this is true")
    print ('var_int = ', var_int)

print ("\nจบการทำงาน")
print ('------------------')
ผลลัพธ์
Selection_005.png
Selection_005.png (4.97 KiB) Viewed 795 times
else

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

var_int = 10
if var_int !=10:
    print ("this is true")
    print ('var_int = ', var_int)

print ("\nจบการทำงาน")
print ('------------------')
ผลลัพธ์
Selection_006.png
Selection_006.png (6.18 KiB) Viewed 795 times

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย chatee supasand » 07/06/2019 4:15 pm

ลองทำดูแล้วทำได้ครับ อธิบายได้ดีมากๆ

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย rangsan » 03/05/2018 4:09 pm

IF Statements (อีฟ สเตรดเม้นท์)

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

num1 = 20
num2 = 30

print "Number 1 is : ",num1
print "Number 2 is : ",num2
print '------------------'

if num1==num2:
    print "Congratulation !!"
elif num1<num2:
    num1+=10
    print "Number 1 Add Success"
else:
    print "Failed"
    
print "Number 1 is : ",num1
print "Number 2 is : ",num2

ผลการรันโค้ด
IF Statement.png
IF Statement.png (21.33 KiB) Viewed 1183 times
ศึกษาจาก : https://www.youtube.com/watch?v=1kH8jsP ... lzdKrpxsMM

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย Patcharanan.0399 » 19/04/2018 4:14 pm

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

var_int = 20
if var_int <> 20:
  print "Is True!"
elif var_int == 15:
  print "Is True!!"
elif var_int == 20:
  print "Is True!!!"
  
print ("\nThank You")

ผลการรัน
ผลลัพธ์ IF satement.jpg
ผลลัพธ์ IF satement.jpg (2.43 KiB) Viewed 1189 times
ศึกษาจาก https://youtu.be/1kH8jsP-0WU

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย Jom07 » 24/01/2018 5:34 pm

ตัวอย่าง IF Statements

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

var_int = 10
if var_int != 10:
    print ("This is true!")
    print("var_int = ", var_int)
print("\nจบการทำงาน")
print("-------------")
ผลรัน

รูปภาพ

ศึกษาข้อมูลจาก : https://www.youtube.com/watch?v=1kH8jsP ... M&index=10

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย Dive Demo » 03/02/2017 9:18 am

อธิบายเข้าใจดีครับ

Re: ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย dawthana » 30/12/2016 9:20 am

สามารถศึกษาเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... ments.html

ทำความรู้จักกับภาษา python (10) : IF Statements (อีฟ สเตรดเม้นท์)

โดย dawthana » 29/12/2016 6:02 pm

IF Statements (อีฟ สเตรดเม้นท์)
ในภาษา python (ไพทอน) จะใช้การแบ่งบล็อคในการควบคุมการทำงานตามเงื่อนไข และจะกำหนดกลุ่มการทำงานด้วยการย่อหน้าแทน

รูปแบบการเขียน if statements
if condition:
  • statement(s)
  • ........................
  • ........................
ตัวอย่างการทำงาน if statement
if_statement.png
if_statement.png (26.93 KiB) Viewed 1281 times
รูปแบบการเขียน if...else Statement
if condition :
  • statement (s)
    ……………….
    ……………….
else :
  • statement (s)
    ……………….
    ……………….
ตัวอย่างการทำงาน if...else Statement
if...else_statement.png
if...else_statement.png (35.22 KiB) Viewed 1281 times
รูปแบบการเขียน elif Statement
if condition1 :
  • statement (s)
elif condition2 :
  • statement (s)
elif condition3 :
  • statement (s)
else
  • statement (s)
ตัวอย่างการทำงาน elif Statement
elif_statement.png
elif_statement.png (38.57 KiB) Viewed 1281 times
-หลัง if condition , elif , else จะตามเด้วยเครื่องหมาย : เสมอ
-ภายใต้เงื่อนไขจะมีกี่ statements ก็ได้แต่ต้องอยู่ภายใต้บล็อคให้ถูกต้อง
-การแบ่งบล็อคจะจบอัตโนมัติเมื่อขึ้น tap ใหม่
-จะมี eilf กี่ชั้นก็อได้หรือไม่มีก็ได้
-ไม่จำเป็นต้องมี else เสมอ หากมีจะมีได้แค่ชั้นเดียวและอยู่ชั้นสุดท้าย

ศึกษาข้อมูลมาจาก https://www.youtube.com/watch?v=1kH8jsP ... lzdKrpxsMM

ข้างบน