الطباعة
print("Hello") >>>
Hello
print(True) >>>
True
print(False) >>>
False
print("Hello 'Ahmed'") >>>
'Hello 'Ahmed
print("Hello 'Ahmed'") >>>
'Hello 'Ahmed
print("Hello\nahmed) >>>
KeyboardInterrupt
print("Hello\nahmed") >>>
Hello
ahmed
print("Hello\"ahmed\"") >>>
"Hello"ahmed
print("Hello\n\'ahmed\'") >>>
Hello
'ahmed'
دمج النصوص
print("Mohamed" + " " + "Mousa") >>>
Mohamed Mousa
العمليات الحسابية
9+9 >>>
18
6*6 >>>
36
6**6 >>>
46656
55/43 >>>
1.2790697674418605
43//55 >>>
7%3 >>>
8%4 >>>
>>>
المتغيرات
num1 = 2 >>>
print(num1) >>>
num2 = 3 >>>
print(num1 ** num2) >>>
num1 = 5 >>>
print(num1) >>>
"name = "Mohamed >>>
print(name) >>>
Mohamed
print("Hello" + name) >>>
HelloMohamed
print("Hello" + " " + name) >>>
Hello Mohamed
b = True >>>
print(b) >>>
True
b = False >>>
print (b) >>>
وتعريف اكثر من متغير
num1, num2, num3 = 3, 6, 9 >>>
print(num1, num2, num3) >>>
963
"name1, name2, name3 = "Mohamed", "Mohamed", "Mousa >>>
>>>
print("Hello" + name1 + " " + name2 + " " + name3) >>>
HelloMohamed Mohamed Mousa
print("Hello" + " " + name1 + " " + name2 + " " + name3) >>>
Hello Mohamed Mohamed Mousa
نواع البيانات و اظهار النوع
num1 = 24 >>>
"name1 = "Mohamed >>>
'name2 = 'Amr >>>
B = True >>>
N = False >>>
print(type(num1), type(name1), type(B)) >>>
>'class 'int'> <class 'str'> <class 'bool<
استالم بيانات من المستخدم
" :Input = "Enter your name please
تحويل االنواع
num1str = 22 >>>
"num2str = "33 >>>
num3 = num1str >>>
print(type(num1str), type(num2str), type(num3)) >>>
>'class 'int'> <class 'str'> <class 'int<
num2str = int(num2str) >>>
print(type(num2str)) >>>
>'class 'int<
print("ABC" + str(123))
ABC123
print(True) >>>
True
print(int(True)) >>>
1
print(int(False)) >>>
print(False) >>>
False
print(bool(1)) >>>
True
print(bool(0)) >>>
False
"A = "A >>>
"a = "a >>>
print(ord(a), ord(A)) >>>
65 97
print(chr(65), chr(97)) >>>
Aa
االستيراد و االرقام العشوائية
import random >>>
print (random.randint(1, 100)) >>>
73
print (random.randint(1, 100)) >>>
58
print (random.randint(1, 100)) >>>
72
print (random.randint(1, 100)) >>>
15
print (random.randint(1, 100)) >>>
82
from random import randint >>>
print(randint(85, 95)) >>>
92
print(randint(85, 95)) >>>
90
print(randint(85, 95)) >>>
90
print(randint(85, 95)) >>>
89
print(randint(85, 95)) >>>
عوامل التخصيص
( العوامل المنطقيةNot / and / or)
True and True >>>
True
True and True and True and True and False >>>
False
False or True or False or False >>>
True
not True >>>
False
not False >>>
True
عوامل المقارنة
x = y = 5 >>>
print(x, y) >>>
55
x==y >>>
True
x!=y >>>
False
x>y >>>
False
X<y >>>
x<y >>>
False
x<=y >>>
True
x>=y >>>
True
>>> y=7
>>> x==y
False
>>> x!=y
True
>>> x<y
True
>>> x>y
False
>>> x<=y
True
>>> x>=y
False
متغير قاموس
>>> person1 = { "name":"Mousa", "salary":3000, "city":"Mansoura", "active":True }
>>> person2 = { "name":"Mohamed", "salary":6000, "city":"Madina", "active":False }
>>> print(person1)
{'name': 'Mousa', 'salary': 3000, 'city': 'Mansoura', 'active': True}
>>> print(person2)
{'name': 'Mohamed', 'salary': 6000, 'city': 'Madina', 'active': False}
>>> print(person1 ["name"])
Mousa
>>> print(person1 ["city"])
Mansoura
>>> print(person2 ["name"])
Mohamed
>>> print(person2 ["city"])
Madina
>>> print(person1 ["active"])
True
>>> print(person2 ["active"])
False
>>> person1 ["name"] = "Ahmed"
>>> print(person1 ["name"])
Ahmed
>>> person1 ["city"] = "Alex"
>>> print(person1 ["city"])
Alex
متغير صف
>>> emp1 = (4211150, "Mousa", 15000)
>>> emp2 = (4211151, "Hossam", 15000)
>>> emp3 = (4211152, "Hesham", 15000)
>>> print(emp1 [1])
Mousa
>>> print(emp2 [0])
4211151
>>> print(emp3 [2])
15000
>>> print(type(emp1))
<class 'tuple'>
>>> print(type(emp1[0]))
<class 'int'>
>>> print(type(emp1 [2]))
<class 'int'>
>>> print(type(emp1 [1]))
<class 'str'>
متغير قائمة
>>> names = ["Mohamed", "Mousa", "Ahmed", "Amr", "Yasser", "Abdo"]
>>> print(names [0])
Mohamed
>>> names [2] = "khaled"
>>> print(names [2])
khaled
>>> data = [4211150, "Mousa", 15000]
>>> print(data [1])
Mousa
متغير قائمة االضافة و الحذف
names = ["Mohamed", "Mousa", "Ahmed", "Amr", "Yasser", "Abdo"]
data = [4211150, "Mousa", 15000]
names.append("Ramy")
names.extend(["Ali", 221, "bakr"])
del(names[6])
print(names)
print(data)
القوائم المتداخلة
family1 = ['a', 'b', 'c', 'd']
family2 = ['e', 'f', 'g', 'h']
family3 = ['i', 'j', 'k', 'l']
family4 = ['m', 'n', 'o', 'p']
home1 = [family1, family2]
home2 = [family3, family4]
print(home1[0])
print(home1[0][1])
#print(home1)
)#print(home2
العدد او الطول 21