دلفي تعليم
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

معلومة على الخفيف في باي ثون info by Python

اذهب الى الأسفل

معلومة على الخفيف في باي ثون info by Python  Empty معلومة على الخفيف في باي ثون info by Python

مُساهمة  djelal 4/5/2022, 12:19 am


معلومة على الخفيف في باي ثون info by Python

variable
المتغيرات
المتغيرات وبعض انواعها

نوع السلسلة
string

x = "Hello"
x = '''Hello'''

variable numbers
المتغيرات الرقمية

متغير صحيح
variable integer

y = 120

متغير حقيقي
variable real

y = 10.25

متغير منطقي

MyBool = True
True
MyBool = False
False


اعداد مركبة
complexes

compNum = 22+5jK

قائمة بانواع مختلفة من القيم

MyList = ["One","Two",0,True]
MyList
['One', 'Two', 0, True]
>>> MyList[0]
'One'

MyTuple = ("One","Two",0)
MyTuple
MyTuple[2] = "True"

MySet = {"One","Two","Tree"}
MySet = {"One","Two","Two"}
MySet
set(['Two', 'One'])

القاموس مكون من مفتاح وقيمة
MyDict = {"firstKey":"Hello","secondKey":0,"test":[1,2,3]}
MyDict["firstKey"]
'Hello'
MyDict["test"]
[1, 2, 3]


الشرطية

if

a = 10
b = 20
c = 30

if a == 10:
print("Yes")
else:
print("No")


>>> if a == 10:
print("Yes")
else:
print("No")

Yes

a=3
b=2

if a>b:
print a


3

a=1

b=2

if a>b:
print a

else:
print b

ادخال من لوحة المفاتيح
a=input("Enter a Number: ")

if a=="1":
print("this is "a)

a=int(input("Enter a Number: "))

if a==1:
print("this is ",a)


الشرطية مركبة

if a == 10 and b == 20:
print("Yes")
else:
print("No")

في حالة الانتماء
if a is b:
print("Yes")
else:
print("No")

No

if a is not b:
print("Yes")
else:
print("No")

Yes


Names =["ibrahim","ali","ahmed"]
if "ali" in Names:
print("ali found")

ali found

if "ali" not in Names:
print("ali not found")
elif "ahmed" in Names:
print("ahmed found")
else:
print("ahmed founds")

ahmed found

الحلقة
for

for x in Names:
print(x)

ibrahim
ali
ahmed


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

الحلقة
while

i = 0
while i < 10:
print(i)
i = i + 1

a=0

while (a<=5):

print a

a+=1

0
1
2
3
4
5


a=5

while (a>=0):

print a

a-=1


5
4
3
2
1
0

الاعداد الزوجية
a=1

while (a<=10):

if a%2==0:

print a

a+=1

2
4
6
8
10

الاعداد الفردية
a=1

while (a<=10):

if a%2!=0:

print a

a+=1

1
3
5
7
9

list=range(0, 5)
print list
--
[0, 1, 2, 3, 4]
--
a=0
while a < len(list):
print list[a]
a+=1
--
0
1
2
3
4


طبع جملة ونوعها

تحويل من كبير ال صغير
import string
print string.upper('helllo')
HELLO

تحويل من صغير الى كبير
import string as s
print s.upper('helllo')
HELLO

var = "Hello World"
print(var)
type(var)
var.upper()
'HELLO WORLD'

الدوال
Functions

def num():
a=3
return a

a=1
print a
print num()
print a

1
3
1

def Myfunc ():
print("Hello World")


Myfunc ()

def Myfunc8 (nam):
print("Hello "+nam)


Myfunc8 ("Ahmed")


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

print(MyAdd(8,12))


Add_func = lambda x,y: x+y
print(Add_func(8,12))


try:
r+r
except:
print("Exception")


try:
r+r
except:
print("Exception")
finally:
print("Error")

r=1
try:
r+r
except:
print("Exception")
else:
print("no Error")

try:
print 'Ali'
print 2/0
print names

except ZeroDivisionError, e:
print e
except NameError, d:
print d


توليد رقم عشوائ
import random
random.randint(0,5)


الفئات
Class


class My_class:
My_Variable = "this is My Variable"
def My_Method(self):
print("this is method")

My_class.My_Method()

My_object = My_class()
My_object.My_Method()









djelal
مبرمج مجتهد

عدد المساهمات : 157
تاريخ التسجيل : 29/04/2015

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى