SDLC: Software Development Life Cycle (SDLC): we must fllow SDLS lifecycle before starting in writing code
| Phase | Detail |
|---|---|
| Stage 1 | Project Planning. ... |
| Stage 2 | Gathering Requirements & Analysis. ... |
| Stage 3 | Design. ... |
| Stage 4 | Coding or Implementation. ... |
| Stage 5 | Testing. ... |
| Stage 6 | Deployment. ... |
| Stage 7 | Maintenance. |
Compiler: It is code that convert the code to code that Operating system can understand and respond ( program will work on specific OS)
Pylint library: Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.
البايثون لايهتم بنوع ال variables float or integer لكن ببقية لغات البرمجه لازم نحدد النوع
اي رقم ماعدى صفر هو ترو
Two strings can be concatenated in Python by simply using the '+' operator between them. More than two strings can be
اذا ماصار الشرط راح يستمر بهاي الوظيفة مدى الحياة
range: command for python only, use 1 as intial value, and 10 as the end value, and dynimaclly know that the conditional statement is
increase value + 1
ex: for number in range(1,10,2):
print("This is medium area")
| Parameter | Detail |
|---|---|
| == | equal |
| != | unequal |
| >= | greater than or equal to |
| <= | less than or equal to |
numbers = range(1,11)
print(type(numbers))
mylist = ["apple","bannana","Cherry"]: this called " array(list) of string"
name = "mohammed": this called " array of charachter
print(len(name)) : len used to find the size of the name.
name = "mohammed"
print(name[0])
Output: m
list3= [True, False, False] : This called " list of boolean
list1 = ['abc', 34, True, 40, "male"]
print(type(list1[1])) : find the clss of datatype
thislist = ["apple", "banana", "cherry"]
# print(len(thislist))
print(thislist[len(thislist) -1])
لذلك لازم انقص واحد من البرنت حتى تصير 3-1, تصير 2 وينطبع اخر سترنك
print(thislist[-1]) يسوي نفس شغل الفوك بس هاي ابسط
sالبايثون اخر رقم بيه هو 0, لما يشوف -1 راح مباشرة يعرف نريد نسوي reverse array, يعني يبلش من الاخير
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[2:5])
هذا راح يطبع فقط: "cherry", "orange", "kiwi" البايثون بطبيعة يستثني اخر رقم الى هو 5 لذلك ازيد المصفوفة حتى اطبع الرقم الاخير الي اريده
print(thislist[2:6])
print(thislist[0:-1]): print all list exclude last one
print(thislist[:4]): print from 0 until 3
print(thislist[2:]): start from 2 until end of list
thislist = ["apple", "banana", "cherry"]
print("before change:", thislist)
thislist.insert(len(thislist), "Melon") : insert used to add value in one of index
print("after change", thislist)
thislist.append("Melon") : append add the value to the end of index
print("after change2", thislist)
thislist = ["apple", "banana", "cherry"]
tropical = ["mango", "pineapple", "papaya"]
thislist.extend(tropical): extend: add list to other list
print(thislist)
output: ['apple', 'banana', 'cherry', 'mango', 'pineapple', 'papaya']
thislist = ["apple", "banana", "cherry"]
print("before change:", thislist)
thislist.remove("banana") : remove index or use: thislist.pop(1) or use statement del thislist[1]
print("after change:", thislist)
output: before change: ['apple', 'banana', 'cherry']
after change: ['apple', 'cherry']
thislist.clear() : clear the list
output after change: []
fruits = ["apple","banana","cherry","kiwi","mango"]
newlist = [x for x in fruits if x.startswith("a")] : find only word that start with " a "
newlist= [x for x in fruits if "a" in x] : find any word contain " a "
newlist = [x for x in fruits if x != "apple"] : get all word except apple
newlist = [x.upper() for x in fruits if x != "apple"] :change all letter to capital
newlist = [x.capitalize() for x in fruits if x != "apple"] : change only first letter to capital
number = [100,50,62,82,23]
number.sort() : ترتيب تصاعدي
number.reverse() : ترتيب تنازلي
mylist = fruits.copy() :: copy from other list
mylist = list(fruits) same upper
list1 = ["a","b","c"]
print(list1.index("b")) : find number of index = output= 2
print(list1.index("b")) : يحسبلي كم مره مكرره هاي القيمة باللست
يعني هو برنامج داخل الكود دائما اعتبر الفاكشن هو برنامج منفصل عن البرنامج الرئيسي في بعض الفكشن ماتخذ انبوت وفيه ماتطلع اوتبوت واكو ماتسوي لااوتبوت ولا انبوت كل وحده وشغله
contacts = {"mostafa":"0123456789", "amr":"9876543210"}
هي عبارة عن key:value مثلا اطبع الكي راح تطلعلي الفاليو
print(contacts["mostafa"])
output: 0123456789
print(contacts.values()): print the vlaues only
output: (['0123456789', '9876543210'])
def my_function(os="win"): "win" هاي ديفلت فاليو اذا ماحطيت القيمة مالته لما استدعي الفكشن راح يطبع الديفلت
اذا حطيت قيمته راح يهمل هاي الديفلت فاليو مثل برنامج بالويندوز اول ماتشغله يكلك تريد اسويلك سكان للدفلت مثلا حرف سي او انت حدد
my_function() : راح يستخدم الديفلت
my_function("linux") : راح يستخدم لنكس ويترك ويندوز
لايفضل عمل برنت داخل الفكشن
الفاكشن الغرض منه طلعلي قيمة ومثلا اخليه بفايربل فالبرنت راح تخرب البرنامج الغرض من الفاكشن طلعلي فاليو اخليه لحاجة ثانية, مثلا انادي الفكشن واخلي الناتج يروح لبرنامج ثاني او يروح ل فكشن الثاني, او الاوتبوت يروح لفريابل ثاني. دائما اخلي الفاكشن يطلع فاليو معينة
def even_or_odd(number):
if number % 2 == 0:
return True : replace print by return
# print("Even")
return ماتظهر اي قيمة ولو اريد اطلع البرنت print(even_or_odd(2)) اخلي البرنت خارج الفكشن
file object allows us to use, access and manipulate all the user accessible files. One can read and write any such files.
my_file = open(file="key.txt", mode="r")
open (): Function in Python: The open () function opens a file and returns a file object as a result
print(dir(open))
نقلب كلشي بالبرنامج الى اوبجكت كل وضيفة بالبرنامج نعبر عنها بأوبجت من مزاياه انه اكتب البرنامج بأكثر من مكان مو بفايل واحد
class student:
def __init__(self, name, age): this is method
import FileOps.FileSearch :
from fileOps.FileSearch import GetFiles : get only GetFiles function.
import os
def GetFiles(FilesPath, Extension="", isRecursive=False):
(Extension="" meaning we can put input or not اكدر احد الايكستينشن او لا اذا اشيل "" راح يجبرني احدد حتى يشتغل البرنامج)
( isRecursive=False هنا الديفلت لا يعني لتبحث داخل الفولدرات الموجودة بالفولدر اذا اريده يبحث اخلي بالبرنامج yes )
FilesList = []
for file in os.listdir(FilesPath):
if file.endswith(Extension):
FilesList.append(file)
return FilesList
import Create_Modules
myfiles = Create_Modules.GetFiles("C:\\windows")
print(myfiles)
for file in os.walk("C:\\"):
print(file)
Root: Dirs: File:
Ex:
Root = C:
Dirs = [] folder in C directory
Files = [] Files in C:\
C:\Windows Root = C:\Windows
read file from txt file ( not recommended in huge size of file, will put directly all size in the memory like 10 gbps ) so we can use read by context manager with
read_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'r' )
print(read_file.read()) read directly from memory
for line in read_file.readlines(): read line by line will also cause low processing in memory
print(line) will be there empty line between each word
print(line.strip()) Erase any empty character
with open("subdomains.lst", 'r') as read_file: read line using context manager
for line in read_file.readlines():
print(line.strip())
write_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'a' )
write_file.write("192.168.1.13 my-pc.com")
if we use upper python code, the permission error will display and we need to use somthing to except the error
فكرة error handling اذا الكود صار بيه error راح يسوي pass ويكمل بقية الكود
try:
write_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'a' )
write_file.write("192.168.1.13 my-pc.com")
except PermissionError:
pass
except FileNotFoundError:
pass
for number in range(10):
print(number)
هتا سويت except اذا طلع الايرور PermissionError هنا راح يتخطاه واذا طلع FileNotFoundError ايضا راح يتخطاه. استخدمه مثلا اذا الفايل ماموجود اكله الفايل ماموجود تريد اسويلك واحد جديد
import socket