ทำความรู้จัก ภาษา python

css

Python เป็นภาษาโปรแกรมที่มีความหลากหลายในการใช้งาน สามารถใช้เขียนโปรแกรมต่าง ๆ ได้หลากหลายรูปแบบ เช่น โปรแกรมบนเว็บ โปรแกรมประยุกต์ และโปรแกรมระบบอื่น ๆ ภาษา Python เป็นภาษาที่มีความง่ายต่อการเขียนและมีการสนับสนุนมากมายจากชุมชนของนักพัฒนา ซึ่งทำให้เป็นภาษาที่นิยมมากในขณะนี้

Python ตัวอย่าง

ตัวอย่าง python

นี่คือตัวอย่างโปรแกรม Python ที่คอมไพล์และเรียกใช้ได้จริง:

นี่คือคำสั่งพิมพ์ของ Python

print(“Hello, World!”)

นี่คือตัวแปรของ Python

x = 10
y = 20
z = x + y
print(z)

นี่คือการใช้งานฟังก์ชัน

def add(a, b):
return a + b

print(add(x, y))

นี่คือการใช้งานลูป for

for i in range(10):
print(i)

นี่คือการใช้งานองค์ประกอบของภาษา Python

list1 = [1, 2, 3]
tuple1 = (4, 5, 6)
set1 = {7, 8, 9}
dict1 = {‘a’: 10, ‘b’: 20, ‘c’: 30}

นี่คือการใช้งานคำสั่ง if

if x > 5:
print(“x is greater than 5”)
elif x == 5:
print(“x is equal to 5”)
else:
print(“x is less than 5”)

ผลลัพธ์ที่คาดว่าจะได้จากการเรียกใช้โปรแกรมนี้คือ:

Hello, World!
30
30
0
1
2
3
4
5
6
7
8
9
x is greater than 5

Div24Hr.COM
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.