├── Persian language ├── Chapter Seven │ └── README.md ├── Chapter Three │ ├── Data Type │ │ ├── float.py │ │ ├── bool.py │ │ ├── int.py │ │ ├── string.py │ │ └── convert.py │ ├── Data Structures │ │ ├── set.py │ │ ├── Tuples.py │ │ ├── list.py │ │ └── Dictionary.py │ ├── Variable │ │ └── variable.py │ └── README.md ├── Chapter Five │ ├── Loop │ │ ├── for.py │ │ └── while.py │ ├── Function │ │ └── functions.py │ ├── Conditionalcommands │ │ └── conditionalcommands.py │ └── README.md ├── Chapter Four │ └── Operators │ │ ├── operators.py │ │ └── README.md ├── Chapter Six │ └── README.md ├── Chapter Two │ └── README.md └── Chapter One │ └── README.md ├── src ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── F3.png ├── ProgrammingEditors.jpg └── 35c6c40d-fa23-4998-8b31-4ee21142679c.avif ├── English language ├── Chapter Three │ ├── Data Type │ │ ├── float.py │ │ ├── bool.py │ │ ├── int.py │ │ ├── string.py │ │ └── convert.py │ ├── Data Structures │ │ ├── set.py │ │ ├── Tuples.py │ │ ├── list.py │ │ └── Dictionary.py │ ├── Variable │ │ └── variable.py │ └── README.md ├── Chapter Five │ ├── Loop │ │ ├── for.py │ │ └── while.py │ ├── Function │ │ └── functions.py │ ├── Conditionalcommands │ │ └── conditionalcommands.py │ └── README.md ├── Chapter Four │ └── Operators │ │ ├── operators.py │ │ └── README.md ├── Chapter Six │ └── README.md ├── Chapter Seven │ └── README.md ├── Chapter Two │ └── README.md └── Chapter One │ └── README.md └── README.md /Persian language/Chapter Seven/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/1.png -------------------------------------------------------------------------------- /src/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/2.png -------------------------------------------------------------------------------- /src/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/3.png -------------------------------------------------------------------------------- /src/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/4.png -------------------------------------------------------------------------------- /src/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/5.png -------------------------------------------------------------------------------- /src/F3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/F3.png -------------------------------------------------------------------------------- /English language/Chapter Three/Data Type/float.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | a = 46.2 4 | b = 40 5 | c = b - a 6 | print(c) 7 | 8 | 9 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Type/float.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | a = 46.2 4 | b = 40 5 | c = b - a 6 | print(c) 7 | 8 | 9 | -------------------------------------------------------------------------------- /English language/Chapter Five/Loop/for.py: -------------------------------------------------------------------------------- 1 | colors = ['red', 'green', 'blue', 'yellow'] 2 | 3 | for color in colors: 4 | print(color) 5 | -------------------------------------------------------------------------------- /Persian language/Chapter Five/Loop/for.py: -------------------------------------------------------------------------------- 1 | colors = ['red', 'green', 'blue', 'yellow'] 2 | 3 | for color in colors: 4 | print(color) 5 | -------------------------------------------------------------------------------- /src/ProgrammingEditors.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/ProgrammingEditors.jpg -------------------------------------------------------------------------------- /English language/Chapter Three/Data Type/bool.py: -------------------------------------------------------------------------------- 1 | 2 | is_raining = True 3 | is_cold = False 4 | print(is_raining) # Output: True 5 | print(is_cold) # Output: False -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Type/bool.py: -------------------------------------------------------------------------------- 1 | 2 | is_raining = True 3 | is_cold = False 4 | print(is_raining) # Output: True 5 | print(is_cold) # Output: False -------------------------------------------------------------------------------- /src/35c6c40d-fa23-4998-8b31-4ee21142679c.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tlikm/introduction-to-the-Python-programming-language/HEAD/src/35c6c40d-fa23-4998-8b31-4ee21142679c.avif -------------------------------------------------------------------------------- /English language/Chapter Three/Data Type/int.py: -------------------------------------------------------------------------------- 1 | a = 20 2 | b = 40 3 | c = b - a 4 | print(c) 5 | 6 | 7 | # Define a value of type int and assign a value to it 8 | age = 30 9 | print(age) 10 | 11 | # Perform arithmetic operations using int changes 12 | year_born = 2021 - age 13 | print("you in the year", year_born, "you are born") -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Type/int.py: -------------------------------------------------------------------------------- 1 | a = 20 2 | b = 40 3 | c = b - a 4 | print(c) 5 | 6 | 7 | # Define a value of type int and assign a value to it 8 | age = 30 9 | print(age) 10 | 11 | # Perform arithmetic operations using int changes 12 | year_born = 2021 - age 13 | print("you in the year", year_born, "you are born") -------------------------------------------------------------------------------- /English language/Chapter Five/Loop/while.py: -------------------------------------------------------------------------------- 1 | count = 0 2 | while count < 5: 3 | print(count) 4 | count += 1 5 | 6 | 7 | 8 | name = str(input("enter your name => ")) 9 | 10 | while name != "Ali": 11 | print("please enter your corect name") 12 | name = str(input("enter your name => ")) 13 | 14 | print("Hi Ali") 15 | 16 | -------------------------------------------------------------------------------- /Persian language/Chapter Five/Loop/while.py: -------------------------------------------------------------------------------- 1 | count = 0 2 | while count < 5: 3 | print(count) 4 | count += 1 5 | 6 | 7 | 8 | name = str(input("enter your name => ")) 9 | 10 | while name != "Ali": 11 | print("please enter your corect name") 12 | name = str(input("enter your name => ")) 13 | 14 | print("Hi Ali") 15 | 16 | -------------------------------------------------------------------------------- /English language/Chapter Five/Function/functions.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess_number(num): 4 | secret_num = random.randint(0, 100) 5 | if num == secret_num: 6 | print("Congratulations! You guessed the number!") 7 | elif num > secret_num: 8 | print("Too high! Try again.") 9 | guess_number(int(input("Enter a number: "))) 10 | else: 11 | print("Too low! Try again.") 12 | guess_number(int(input("Enter a number: "))) 13 | 14 | guess_number(int(input("Enter a number: "))) 15 | 16 | -------------------------------------------------------------------------------- /Persian language/Chapter Five/Function/functions.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess_number(num): 4 | secret_num = random.randint(0, 100) 5 | if num == secret_num: 6 | print("Congratulations! You guessed the number!") 7 | elif num > secret_num: 8 | print("Too high! Try again.") 9 | guess_number(int(input("Enter a number: "))) 10 | else: 11 | print("Too low! Try again.") 12 | guess_number(int(input("Enter a number: "))) 13 | 14 | guess_number(int(input("Enter a number: "))) 15 | 16 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Structures/set.py: -------------------------------------------------------------------------------- 1 | my_list = [1, 2, 3, 3, 4, 5, 5] 2 | my_set = set(my_list) 3 | print(my_set) # Output: {1, 2, 3, 4, 5} 4 | 5 | 6 | # Union of two sets 7 | set1 = {1, 2, 3} 8 | set2 = {3, 4, 5} 9 | print(set1.union(set2)) # Output: {1, 2, 3, 4, 5} 10 | 11 | # Intersection of two sets 12 | set1 = {1, 2, 3} 13 | set2 = {3, 4, 5} 14 | print(set1.intersection(set2)) # Output: {3} 15 | 16 | # Difference of two sets 17 | set1 = {1, 2, 3} 18 | set2 = {3, 4, 5} 19 | print(set1.difference(set2)) # Output: {1, 2} 20 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Structures/set.py: -------------------------------------------------------------------------------- 1 | my_list = [1, 2, 3, 3, 4, 5, 5] 2 | my_set = set(my_list) 3 | print(my_set) # Output: {1, 2, 3, 4, 5} 4 | 5 | 6 | # Union of two sets 7 | set1 = {1, 2, 3} 8 | set2 = {3, 4, 5} 9 | print(set1.union(set2)) # Output: {1, 2, 3, 4, 5} 10 | 11 | # Intersection of two sets 12 | set1 = {1, 2, 3} 13 | set2 = {3, 4, 5} 14 | print(set1.intersection(set2)) # Output: {3} 15 | 16 | # Difference of two sets 17 | set1 = {1, 2, 3} 18 | set2 = {3, 4, 5} 19 | print(set1.difference(set2)) # Output: {1, 2} 20 | -------------------------------------------------------------------------------- /English language/Chapter Three/Variable/variable.py: -------------------------------------------------------------------------------- 1 | # First example - integer variables 2 | 3 | a = 5 4 | b = 10 5 | c = a + b 6 | print(c) # Output: 15 7 | 8 | # Second example - string variables 9 | 10 | name = "John" 11 | message = "Hello, " + name + "!" 12 | print(message) # Output: Hello, John! 13 | 14 | # Third example - Boolean variables 15 | 16 | is_raining = True 17 | is_cold = False 18 | print(is_raining) # Output: True 19 | print(is_cold) # Output: False 20 | 21 | # Fourth example - floating point variables 22 | 23 | x = 3.14 24 | y = 2.5 25 | z = x * y 26 | print(z) # Output: 7.85 27 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Variable/variable.py: -------------------------------------------------------------------------------- 1 | # First example - integer variables 2 | 3 | a = 5 4 | b = 10 5 | c = a + b 6 | print(c) # Output: 15 7 | 8 | # Second example - string variables 9 | 10 | name = "John" 11 | message = "Hello, " + name + "!" 12 | print(message) # Output: Hello, John! 13 | 14 | # Third example - Boolean variables 15 | 16 | is_raining = True 17 | is_cold = False 18 | print(is_raining) # Output: True 19 | print(is_cold) # Output: False 20 | 21 | # Fourth example - floating point variables 22 | 23 | x = 3.14 24 | y = 2.5 25 | z = x * y 26 | print(z) # Output: 7.85 27 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Structures/Tuples.py: -------------------------------------------------------------------------------- 1 | names = [] # ایجاد یک لیست خالی 2 | 3 | # دریافت ۵ نام از کاربر و ذخیره آن‌ها در لیست 4 | for i in range(5): 5 | name = input("Enter a name: ") 6 | names.append(name) 7 | mytuple = tuple(names) 8 | 9 | # چاپ تمامی نام‌های ذخیره شده در لیست 10 | print("The names are:") 11 | for name in names: 12 | print(name) 13 | 14 | print(mytuple) 15 | 16 | 17 | # تعریف یک tuple جدید 18 | person = ("John", "Doe", 27, "123-456-7890") 19 | 20 | # دسترسی به اطلاعات در یک tuple با استفاده از indexing 21 | print("Name:", person[0], person[1]) 22 | print("Age:", person[2]) 23 | print("Phone:", person[3]) -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Structures/Tuples.py: -------------------------------------------------------------------------------- 1 | names = [] # ایجاد یک لیست خالی 2 | 3 | # دریافت ۵ نام از کاربر و ذخیره آن‌ها در لیست 4 | for i in range(5): 5 | name = input("Enter a name: ") 6 | names.append(name) 7 | mytuple = tuple(names) 8 | 9 | # چاپ تمامی نام‌های ذخیره شده در لیست 10 | print("The names are:") 11 | for name in names: 12 | print(name) 13 | 14 | print(mytuple) 15 | 16 | 17 | # تعریف یک tuple جدید 18 | person = ("John", "Doe", 27, "123-456-7890") 19 | 20 | # دسترسی به اطلاعات در یک tuple با استفاده از indexing 21 | print("Name:", person[0], person[1]) 22 | print("Age:", person[2]) 23 | print("Phone:", person[3]) -------------------------------------------------------------------------------- /English language/Chapter Five/Conditionalcommands/conditionalcommands.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | #syn 4 | 5 | # if condition1: 6 | # code to execute if condition1 is True 7 | # elif condition2: 8 | # code to execute if condition1 is False, but condition2 is True 9 | # else: 10 | # code to execute if neither condition is True 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | age = 21 19 | if age < 18: 20 | print("You are not old enough to vote yet.") 21 | elif age < 21: 22 | print("You can vote, but you cannot buy alcohol.") 23 | else: 24 | print("You can vote and buy alcohol.") 25 | 26 | 27 | num = 5 28 | 29 | if num >= 0: 30 | print("The number is positive") 31 | else: 32 | print("The number is negative") 33 | 34 | 35 | 36 | name = input("What is your name? ") 37 | 38 | if name == "Saeed": 39 | print("Hello, Saeed!") 40 | else: 41 | print("Hello, "+name+".") 42 | -------------------------------------------------------------------------------- /Persian language/Chapter Five/Conditionalcommands/conditionalcommands.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | #syn 4 | 5 | # if condition1: 6 | # code to execute if condition1 is True 7 | # elif condition2: 8 | # code to execute if condition1 is False, but condition2 is True 9 | # else: 10 | # code to execute if neither condition is True 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | age = 21 19 | if age < 18: 20 | print("You are not old enough to vote yet.") 21 | elif age < 21: 22 | print("You can vote, but you cannot buy alcohol.") 23 | else: 24 | print("You can vote and buy alcohol.") 25 | 26 | 27 | num = 5 28 | 29 | if num >= 0: 30 | print("The number is positive") 31 | else: 32 | print("The number is negative") 33 | 34 | 35 | 36 | name = input("What is your name? ") 37 | 38 | if name == "Saeed": 39 | print("Hello, Saeed!") 40 | else: 41 | print("Hello, "+name+".") 42 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Type/string.py: -------------------------------------------------------------------------------- 1 | #str 2 | str1 = "Hello, world!" 3 | str2 = 'It is a nice day.' 4 | 5 | #more then one line 6 | txt = """Lorem ipsum dolor sit amet, 7 | consectetur adipiscing elit, 8 | sed do eiusmod tempor incididunt 9 | ut labore et dolore magna aliqua.""" 10 | 11 | 12 | a = "Alireza " 13 | b = "Allahyarian" 14 | print(a+b) 15 | 16 | 17 | #metod 18 | string = "python is amazing" 19 | print(string.capitalize()) #capitalize(): 20 | # Output: "Python is amazing" 21 | 22 | string = "python is amazing" 23 | print(string.upper()) 24 | # Output: "PYTHON IS AMAZING" 25 | 26 | string = "PYTHON IS AMAZING" 27 | print(string.lower()) 28 | # Output: "python is amazing" 29 | 30 | string = "Python, is, amazing" 31 | lst = string.split(",") 32 | print(lst) 33 | # Output: ['Python', ' is', ' amazing'] 34 | 35 | string = "Python is amazing" 36 | new_string = string.replace("Python", "Java") 37 | print(new_string) 38 | # Output: "Java is amazing" 39 | 40 | string = "PYTHON IS AMAZING" 41 | print(len(string)) 42 | # Output: 17 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Type/string.py: -------------------------------------------------------------------------------- 1 | #str 2 | str1 = "Hello, world!" 3 | str2 = 'It is a nice day.' 4 | 5 | #more then one line 6 | txt = """Lorem ipsum dolor sit amet, 7 | consectetur adipiscing elit, 8 | sed do eiusmod tempor incididunt 9 | ut labore et dolore magna aliqua.""" 10 | 11 | 12 | a = "Alireza " 13 | b = "Allahyarian" 14 | print(a+b) 15 | 16 | 17 | #metod 18 | string = "python is amazing" 19 | print(string.capitalize()) #capitalize(): 20 | # Output: "Python is amazing" 21 | 22 | string = "python is amazing" 23 | print(string.upper()) 24 | # Output: "PYTHON IS AMAZING" 25 | 26 | string = "PYTHON IS AMAZING" 27 | print(string.lower()) 28 | # Output: "python is amazing" 29 | 30 | string = "Python, is, amazing" 31 | lst = string.split(",") 32 | print(lst) 33 | # Output: ['Python', ' is', ' amazing'] 34 | 35 | string = "Python is amazing" 36 | new_string = string.replace("Python", "Java") 37 | print(new_string) 38 | # Output: "Java is amazing" 39 | 40 | string = "PYTHON IS AMAZING" 41 | print(len(string)) 42 | # Output: 17 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Structures/list.py: -------------------------------------------------------------------------------- 1 | primes = [2, 3, 5, 7] 2 | 3 | numbers = list(range(1, 6)) 4 | 5 | # ----------------------------------------------------------------- # 6 | 7 | my_list = [1, 2, 3] #append 8 | my_list.append(4) 9 | print(my_list) # خروجی: [1, 2, 3, 4] 10 | 11 | my_list = [1, 2, 3] 12 | my_list.extend([4, 5]) 13 | print(my_list) # خروجی: [1, 2, 3, 4, 5] 14 | 15 | my_list = [1, 2, 3] 16 | my_list.insert(1, 4) 17 | print(my_list) # خروجی: [1, 4, 2, 3] 18 | 19 | my_list = [1, 2, 3] 20 | my_list.remove(2) 21 | print(my_list) # خروجی: [1, 3] 22 | 23 | my_list = [1, 2, 3] 24 | popped = my_list.pop() 25 | print(popped) # خروجی: 3 26 | print(my_list) # خروجی: [1, 2] 27 | 28 | my_list = [3, 1, 4, 2, 5] 29 | my_list.sort() 30 | print(my_list) # خروجی: [1, 2, 3, 4, 5] 31 | 32 | # ----------------------------------------------------------------- # 33 | 34 | numbers = [] # ایجاد یک لیست خالی 35 | 36 | # دریافت ۵ عدد از کاربر و ذخیره آن‌ها در لیست 37 | 38 | num = int(input("Enter a number: ")) 39 | numbers.append(num) 40 | 41 | # محاسبه مجموع عناصر لیست 42 | total = sum(numbers) 43 | 44 | # چاپ مجموع عناصر لیست 45 | print("The sum of the numbers is:", total) 46 | 47 | # ----------------------------------------------------------------- # 48 | 49 | names = [] # ایجاد یک لیست خالی 50 | 51 | # دریافت ۵ نام از کاربر و ذخیره آن‌ها در لیست 52 | for i in range(5): 53 | name = input("Enter a name: ") 54 | names.append(name) 55 | 56 | # چاپ تمامی نام‌های ذخیره شده در لیست 57 | print("The names are:") 58 | for name in names: 59 | print(name) 60 | 61 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Structures/list.py: -------------------------------------------------------------------------------- 1 | primes = [2, 3, 5, 7] 2 | 3 | numbers = list(range(1, 6)) 4 | 5 | # ----------------------------------------------------------------- # 6 | 7 | my_list = [1, 2, 3] #append 8 | my_list.append(4) 9 | print(my_list) # خروجی: [1, 2, 3, 4] 10 | 11 | my_list = [1, 2, 3] 12 | my_list.extend([4, 5]) 13 | print(my_list) # خروجی: [1, 2, 3, 4, 5] 14 | 15 | my_list = [1, 2, 3] 16 | my_list.insert(1, 4) 17 | print(my_list) # خروجی: [1, 4, 2, 3] 18 | 19 | my_list = [1, 2, 3] 20 | my_list.remove(2) 21 | print(my_list) # خروجی: [1, 3] 22 | 23 | my_list = [1, 2, 3] 24 | popped = my_list.pop() 25 | print(popped) # خروجی: 3 26 | print(my_list) # خروجی: [1, 2] 27 | 28 | my_list = [3, 1, 4, 2, 5] 29 | my_list.sort() 30 | print(my_list) # خروجی: [1, 2, 3, 4, 5] 31 | 32 | # ----------------------------------------------------------------- # 33 | 34 | numbers = [] # ایجاد یک لیست خالی 35 | 36 | # دریافت ۵ عدد از کاربر و ذخیره آن‌ها در لیست 37 | 38 | num = int(input("Enter a number: ")) 39 | numbers.append(num) 40 | 41 | # محاسبه مجموع عناصر لیست 42 | total = sum(numbers) 43 | 44 | # چاپ مجموع عناصر لیست 45 | print("The sum of the numbers is:", total) 46 | 47 | # ----------------------------------------------------------------- # 48 | 49 | names = [] # ایجاد یک لیست خالی 50 | 51 | # دریافت ۵ نام از کاربر و ذخیره آن‌ها در لیست 52 | for i in range(5): 53 | name = input("Enter a name: ") 54 | names.append(name) 55 | 56 | # چاپ تمامی نام‌های ذخیره شده در لیست 57 | print("The names are:") 58 | for name in names: 59 | print(name) 60 | 61 | -------------------------------------------------------------------------------- /English language/Chapter Four/Operators/operators.py: -------------------------------------------------------------------------------- 1 | # ---------- Arithmetic operators -----------# 2 | 3 | x = 10 4 | y = 5 5 | 6 | print(x + y) # 15 7 | print(x - y) # 5 8 | print(x * y) # 50 9 | print(x / y) # 2.0 10 | print(x % y) # 0 11 | print(x ** y) # 100000 12 | print(x // y) # 2 13 | 14 | 15 | # ---------- comparison operators -----------# 16 | x = 10 17 | y = 5 18 | 19 | print(x == y) # False 20 | print(x != y) # True 21 | print(x > y) # True 22 | print(x < y) # False 23 | print(x >= y) # True 24 | print(x <= y) # False 25 | 26 | 27 | 28 | # ---------- Assignment operators -----------# 29 | 30 | x = 5 31 | x += 3 32 | print(x) # output: 8 33 | 34 | x = 5 35 | x -= 3 36 | print(x) # output: 2 37 | 38 | x = 5 39 | x *= 3 40 | print(x) # output: 15 41 | 42 | x = 6 43 | x /= 3 44 | print(x) # output: 2.0 45 | 46 | x = 7 47 | x %= 3 48 | print(x) # output: 1 49 | 50 | x = 7 51 | x //= 3 52 | print(x) # output: 2 53 | 54 | x = 2 55 | x **= 3 56 | print(x) # output: 8 57 | 58 | 59 | 60 | # ---------- logical operators -----------# 61 | 62 | x = 10 63 | y = 5 64 | 65 | print(x > 5 and y < 10) # True 66 | print(x > 5 or y > 10) # True 67 | print(not(x == y)) # True 68 | 69 | 70 | # ---------- membership operators -----------# 71 | 72 | x = ["apple", "banana"] 73 | print("banana" in x) # True 74 | print("cherry" not in x) # True 75 | 76 | 77 | 78 | # ---------- Identity operators -----------# 79 | 80 | # is a comparison with the operator 81 | a = [1, 2, 3] 82 | b = a 83 | print(b is a) # Output: True 84 | 85 | c = [1, 2, 3] 86 | print(c is a) # Output: False 87 | 88 | # compares the absence with the not operator 89 | d = "Hello" 90 | e = "World" 91 | print(d is not e) # Output: True 92 | 93 | f = "Hello" 94 | print(d is not f) # Output: False 95 | -------------------------------------------------------------------------------- /Persian language/Chapter Four/Operators/operators.py: -------------------------------------------------------------------------------- 1 | # ---------- Arithmetic operators -----------# 2 | 3 | x = 10 4 | y = 5 5 | 6 | print(x + y) # 15 7 | print(x - y) # 5 8 | print(x * y) # 50 9 | print(x / y) # 2.0 10 | print(x % y) # 0 11 | print(x ** y) # 100000 12 | print(x // y) # 2 13 | 14 | 15 | # ---------- comparison operators -----------# 16 | x = 10 17 | y = 5 18 | 19 | print(x == y) # False 20 | print(x != y) # True 21 | print(x > y) # True 22 | print(x < y) # False 23 | print(x >= y) # True 24 | print(x <= y) # False 25 | 26 | 27 | 28 | # ---------- Assignment operators -----------# 29 | 30 | x = 5 31 | x += 3 32 | print(x) # output: 8 33 | 34 | x = 5 35 | x -= 3 36 | print(x) # output: 2 37 | 38 | x = 5 39 | x *= 3 40 | print(x) # output: 15 41 | 42 | x = 6 43 | x /= 3 44 | print(x) # output: 2.0 45 | 46 | x = 7 47 | x %= 3 48 | print(x) # output: 1 49 | 50 | x = 7 51 | x //= 3 52 | print(x) # output: 2 53 | 54 | x = 2 55 | x **= 3 56 | print(x) # output: 8 57 | 58 | 59 | 60 | # ---------- logical operators -----------# 61 | 62 | x = 10 63 | y = 5 64 | 65 | print(x > 5 and y < 10) # True 66 | print(x > 5 or y > 10) # True 67 | print(not(x == y)) # True 68 | 69 | 70 | # ---------- membership operators -----------# 71 | 72 | x = ["apple", "banana"] 73 | print("banana" in x) # True 74 | print("cherry" not in x) # True 75 | 76 | 77 | 78 | # ---------- Identity operators -----------# 79 | 80 | # is a comparison with the operator 81 | a = [1, 2, 3] 82 | b = a 83 | print(b is a) # Output: True 84 | 85 | c = [1, 2, 3] 86 | print(c is a) # Output: False 87 | 88 | # compares the absence with the not operator 89 | d = "Hello" 90 | e = "World" 91 | print(d is not e) # Output: True 92 | 93 | f = "Hello" 94 | print(d is not f) # Output: False 95 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Type/convert.py: -------------------------------------------------------------------------------- 1 | num = 123 2 | str_num = str(num) 3 | print(type(str_num)) # 4 | 5 | 6 | str_num = "456" 7 | num = int(str_num) 8 | print(type(num)) # 9 | 10 | 11 | float_num = 3.14 12 | int_num = int(float_num) 13 | print(type(int_num)) # 14 | 15 | 16 | int_num = 42 17 | float_num = float(int_num) 18 | print(type(float_num)) # 19 | 20 | 21 | int_num = 0 22 | is_true = bool(int_num) 23 | print(type(is_true)) # 24 | 25 | is_true = True 26 | int_num = int(is_true) 27 | print(type(int_num)) # 28 | 29 | 30 | my_string = "Hello, World!" 31 | my_list = list(my_string) 32 | print(my_list) # ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'] 33 | 34 | 35 | my_list = ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'] 36 | my_string = ''.join(my_list) 37 | print(my_string) # 'Hello, World!' 38 | 39 | 40 | my_tuple = ('apple', 'banana', 'cherry') 41 | my_list = list(my_tuple) 42 | print(my_list) # ['apple', 'banana', 'cherry'] 43 | 44 | 45 | my_list = ['apple', 'banana', 'cherry'] 46 | my_tuple = tuple(my_list) 47 | print(my_tuple) # ('apple', 'banana', 'cherry') 48 | 49 | 50 | my_string = '{"name": "John", "age": 30, "city": "New York"}' 51 | my_dict = dict(my_string) 52 | print(my_dict) # {'{': None, '"': None, 'n': None, 'a': None, 'm': None, 'e': None, ... 53 | 54 | 55 | my_dict = {"name": "John", "age": 30, "city": "New York"} 56 | my_string = str(my_dict) 57 | print(my_string) # "{'name': 'John', 'age': 30, 'city': 'New York'}" 58 | 59 | 60 | str_list = ["3", "5", "7", "9"] 61 | num_list = [int(x) for x in str_list] 62 | print(num_list) # [3, 5, 7, 9] 63 | 64 | 65 | num_list = [1, 2, 3, 4, 5] 66 | str_list = [str(x) for x in num_list] 67 | print(str_list) # ['1', '2', '3', '4', '5'] 68 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Type/convert.py: -------------------------------------------------------------------------------- 1 | num = 123 2 | str_num = str(num) 3 | print(type(str_num)) # 4 | 5 | 6 | str_num = "456" 7 | num = int(str_num) 8 | print(type(num)) # 9 | 10 | 11 | float_num = 3.14 12 | int_num = int(float_num) 13 | print(type(int_num)) # 14 | 15 | 16 | int_num = 42 17 | float_num = float(int_num) 18 | print(type(float_num)) # 19 | 20 | 21 | int_num = 0 22 | is_true = bool(int_num) 23 | print(type(is_true)) # 24 | 25 | is_true = True 26 | int_num = int(is_true) 27 | print(type(int_num)) # 28 | 29 | 30 | my_string = "Hello, World!" 31 | my_list = list(my_string) 32 | print(my_list) # ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'] 33 | 34 | 35 | my_list = ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'] 36 | my_string = ''.join(my_list) 37 | print(my_string) # 'Hello, World!' 38 | 39 | 40 | my_tuple = ('apple', 'banana', 'cherry') 41 | my_list = list(my_tuple) 42 | print(my_list) # ['apple', 'banana', 'cherry'] 43 | 44 | 45 | my_list = ['apple', 'banana', 'cherry'] 46 | my_tuple = tuple(my_list) 47 | print(my_tuple) # ('apple', 'banana', 'cherry') 48 | 49 | 50 | my_string = '{"name": "John", "age": 30, "city": "New York"}' 51 | my_dict = dict(my_string) 52 | print(my_dict) # {'{': None, '"': None, 'n': None, 'a': None, 'm': None, 'e': None, ... 53 | 54 | 55 | my_dict = {"name": "John", "age": 30, "city": "New York"} 56 | my_string = str(my_dict) 57 | print(my_string) # "{'name': 'John', 'age': 30, 'city': 'New York'}" 58 | 59 | 60 | str_list = ["3", "5", "7", "9"] 61 | num_list = [int(x) for x in str_list] 62 | print(num_list) # [3, 5, 7, 9] 63 | 64 | 65 | num_list = [1, 2, 3, 4, 5] 66 | str_list = [str(x) for x in num_list] 67 | print(str_list) # ['1', '2', '3', '4', '5'] 68 | -------------------------------------------------------------------------------- /English language/Chapter Three/Data Structures/Dictionary.py: -------------------------------------------------------------------------------- 1 | # Build a dictionary 2 | my_dict = {'name': 'Maryam', 'age': 25, 'country': 'Iran'} 3 | 4 | # Access dictionary elements using keys 5 | print(my_dict['name']) # output: Maryam 6 | print(my_dict['age']) # output: 25 7 | 8 | # Change the value of a key in the dictionary 9 | my_dict['age'] = 30 10 | print(my_dict['age']) # output: 30 11 | 12 | # Add a new key-value pair to the dictionary 13 | my_dict['profession'] = 'Engineer' 14 | print(my_dict) 15 | # output: {'name': 'Maryam', 'age': 30, 'country': 'Iran', 'profession': 'Engineer'} 16 | 17 | # ----------------------------------------------------------------- # 18 | 19 | # clear(): clear all dictionary items 20 | d = {1: 'red', 2: 'blue', 3: 'green'} 21 | d.clear() 22 | print(d) # Output: {} 23 | 24 | 25 | #copy(): Copy a dictionary 26 | d = {1: 'red', 2: 'blue', 3: 'green'} 27 | d1 = d.copy() 28 | print(d1) # Output: {1: 'red', 2: 'blue', 3: 'green'} 29 | 30 | 31 | #get(): Gets the value corresponding to a key, returning the default value if the key does not exist. 32 | d = {1: 'red', 2: 'blue', 3: 'green'} 33 | print(d.get(1)) # Output: 'red' 34 | print(d.get(4, 'No color')) # Output: 'No color' 35 | 36 | 37 | #items(): return all items of the dictionary 38 | d = {1: 'red', 2: 'blue', 3: 'green'} 39 | print(d.items()) # Output: dict_items([(1, 'red'), (2, 'blue'), (3, 'green')]) 40 | 41 | 42 | #keys(): return all keys of the dictionary 43 | d = {1: 'red', 2: 'blue', 3: 'green'} 44 | print(d.keys()) # Output: dict_keys([1, 2, 3]) 45 | 46 | 47 | #values(): return all dictionary values 48 | d = {1: 'red', 2: 'blue', 3: 'green'} 49 | print(d.values()) # Output: dict_values(['red', 'blue', 'green']) 50 | 51 | 52 | #pop(): remove an item from the dictionary using the corresponding key 53 | d = {1: 'red', 2: 'blue', 3: 'green'} 54 | d.pop(2) 55 | print(d) # Output: {1: 'red', 3: 'green'} 56 | 57 | 58 | #update(): update the dictionary by adding another dictionary 59 | d = {1: 'red', 2: 'blue', 3: 'green'} 60 | d1 = {4: 'yellow'} 61 | d.update(d1) 62 | print(d) # Output: {1: 'red', 2: 'blue', 3: 'green', 4: 'yellow'} 63 | 64 | # ----------------------------------------------------------------- # 65 | 66 | text = "In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available." 67 | text = text.lower() 68 | words = text.split(" ") 69 | 70 | word_count = {} 71 | 72 | for word in words: 73 | count = word_count.get(word, 0) 74 | word_count[word] = count + 1 75 | 76 | print(word_count) 77 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/Data Structures/Dictionary.py: -------------------------------------------------------------------------------- 1 | # Build a dictionary 2 | my_dict = {'name': 'Maryam', 'age': 25, 'country': 'Iran'} 3 | 4 | # Access dictionary elements using keys 5 | print(my_dict['name']) # output: Maryam 6 | print(my_dict['age']) # output: 25 7 | 8 | # Change the value of a key in the dictionary 9 | my_dict['age'] = 30 10 | print(my_dict['age']) # output: 30 11 | 12 | # Add a new key-value pair to the dictionary 13 | my_dict['profession'] = 'Engineer' 14 | print(my_dict) 15 | # output: {'name': 'Maryam', 'age': 30, 'country': 'Iran', 'profession': 'Engineer'} 16 | 17 | # ----------------------------------------------------------------- # 18 | 19 | # clear(): clear all dictionary items 20 | d = {1: 'red', 2: 'blue', 3: 'green'} 21 | d.clear() 22 | print(d) # Output: {} 23 | 24 | 25 | #copy(): Copy a dictionary 26 | d = {1: 'red', 2: 'blue', 3: 'green'} 27 | d1 = d.copy() 28 | print(d1) # Output: {1: 'red', 2: 'blue', 3: 'green'} 29 | 30 | 31 | #get(): Gets the value corresponding to a key, returning the default value if the key does not exist. 32 | d = {1: 'red', 2: 'blue', 3: 'green'} 33 | print(d.get(1)) # Output: 'red' 34 | print(d.get(4, 'No color')) # Output: 'No color' 35 | 36 | 37 | #items(): return all items of the dictionary 38 | d = {1: 'red', 2: 'blue', 3: 'green'} 39 | print(d.items()) # Output: dict_items([(1, 'red'), (2, 'blue'), (3, 'green')]) 40 | 41 | 42 | #keys(): return all keys of the dictionary 43 | d = {1: 'red', 2: 'blue', 3: 'green'} 44 | print(d.keys()) # Output: dict_keys([1, 2, 3]) 45 | 46 | 47 | #values(): return all dictionary values 48 | d = {1: 'red', 2: 'blue', 3: 'green'} 49 | print(d.values()) # Output: dict_values(['red', 'blue', 'green']) 50 | 51 | 52 | #pop(): remove an item from the dictionary using the corresponding key 53 | d = {1: 'red', 2: 'blue', 3: 'green'} 54 | d.pop(2) 55 | print(d) # Output: {1: 'red', 3: 'green'} 56 | 57 | 58 | #update(): update the dictionary by adding another dictionary 59 | d = {1: 'red', 2: 'blue', 3: 'green'} 60 | d1 = {4: 'yellow'} 61 | d.update(d1) 62 | print(d) # Output: {1: 'red', 2: 'blue', 3: 'green', 4: 'yellow'} 63 | 64 | # ----------------------------------------------------------------- # 65 | 66 | text = "In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available." 67 | text = text.lower() 68 | words = text.split(" ") 69 | 70 | word_count = {} 71 | 72 | for word in words: 73 | count = word_count.get(word, 0) 74 | word_count[word] = count + 1 75 | 76 | print(word_count) 77 | -------------------------------------------------------------------------------- /Persian language/Chapter Six/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹موضوعاتی که در این فصل بحث می کنیم: 2 | 3 | - Libraries in Python (The concept of script, module, package, library and framework) 4 | 5 | 6 | ## 💎 مغهوم script در پایتون 7 | 8 | #### 🔷 در پایتون، اسکریپت برنامه ای است که به زبان برنامه نویسی پایتون نوشته شده است که می تواند از یک رابط خط فرمان یا از یک محیط توسعه یکپارچه (IDE) اجرا شود. 9 | اسکریپت پایتون یک فایل حاوی کد پایتون است که معمولاً با پسوند py. ذخیره می شود. هنگامی که اسکریپت اجرا می شود، مفسر پایتون کد را می خواند و آن را خط به خط اجرا می کند. از اسکریپت های پایتون می توان برای طیف وسیعی از وظایف، مانند خودکارسازی وظایف تکراری، پردازش داده ها یا ساخت برنامه های پیچیده استفاده کرد. 10 | 11 |
12 | 13 | ## 💎مفهوم module در پایتون 14 | 15 | #### 🔷 در پایتون، ماژول ها به سادگی فایل هایی با “. پسوند py حاوی کد پایتون است که می تواند در برنامه پایتون دیگری وارد شود. به زبان ساده، ما می‌توانیم یک ماژول را همان کتابخانه کد یا فایلی در نظر بگیریم که شامل مجموعه‌ای از توابع است که می‌خواهید در برنامه خود قرار دهید. 16 | 17 |
18 | 19 | ## 💎مغهوم package در پایتون 20 | 21 | #### 🔷 به زبان بسیار ساده، یک بسته در پایتون (Paython Package) تعدادی ماژول است که در یک پوشه قرار می گیرد! معمولا ماژول هایی که در یک پکیج قرار می گیرند هدفی مشابه دارند. به عنوان مثال، بخش مدیریت سطح دسترسی (احراز هویت) یک برنامه یا مدیریت کاربر می تواند یک بسته باشد. 22 |
23 | 24 | ## 💎مفهوم library در پایتون 25 | 26 | #### 🔷 در برنامه نویسی، کتابخانه مجموعه ای از کدهای از پیش نوشته شده است که می تواند توسط برنامه های دیگر مورد استفاده مجدد قرار گیرد. یک کتابخانه معمولاً شامل مجموعه‌ای از توابع، روال‌ها، کلاس‌ها یا ماژول‌ها است که می‌تواند توسط یک برنامه کاربردی برای انجام وظایف خاص، مانند ورودی/خروجی فایل، ارتباطات شبکه، دستکاری داده‌ها و غیره فراخوانی شود. 27 | در پایتون، یک کتابخانه معمولاً به عنوان یک ماژول یا مجموعه ای از ماژول ها بسته بندی می شود که می توانند وارد و در یک برنامه استفاده شوند. 28 | 29 |
30 | 31 | ## 💎 مفهوم framework در پایتون 32 | 33 | #### 🔷 در پایتون، چارچوب مجموعه‌ای از ماژول‌ها، کتابخانه‌ها و ابزارهایی است که برای کمک به توسعه‌دهندگان در ساخت برنامه‌های کاربردی کارآمدتر طراحی شده‌اند. یک چارچوب مجموعه‌ای از قراردادها، بهترین شیوه‌ها و کدهای قابل استفاده مجدد را ارائه می‌کند که می‌توانند برای ساده‌سازی فرآیند توسعه و سرعت بخشیدن به زمان عرضه برنامه به بازار استفاده شوند. 34 | فریم‌ورک‌ها معمولاً پایه‌ای برای ساخت برنامه‌های کاربردی وب، برنامه‌های دسکتاپ، بازی‌ها یا سایر انواع نرم‌افزار فراهم می‌کنند. برخی از فریمورک‌های محبوب پایتون عبارتند از جنگو، فلاسک، پیرامید و چری پای و غیره. این چارچوب‌ها مجموعه‌ای از ابزارها و کتابخانه‌ها را ارائه می‌کنند که به توسعه‌دهندگان کمک می‌کنند تا کارهای رایجی مانند مسیریابی، دسترسی به پایگاه داده، قالب‌بندی، امنیت و غیره را انجام دهند. 35 | 36 | *** 37 | 38 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 39 | 40 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 41 | -------------------------------------------------------------------------------- /English language/Chapter Six/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹The topics we discuss in this chapter: 2 | 3 | - Libraries in Python (The concept of script, module, package, library and framework) 4 | 5 | 6 | ## 💎The concept of script 7 | 8 | #### 🔷 In Python, a script is a program written in the Python programming language that can be executed from a command line interface or from an integrated development environment (IDE). 9 | A Python script is a file containing Python code, typically saved with a .py extension. When the script is executed, the Python interpreter reads the code and executes it line by line. Python scripts can be used for a wide range of tasks, such as automating repetitive tasks, processing data, or building complex applications. 10 | 11 |
12 | 13 | ## 💎The concept of module 14 | 15 | #### 🔷 In Python, Modules are simply files with the “. py” extension containing Python code that can be imported inside another Python Program. In simple terms, we can consider a module to be the same as a code library or a file that contains a set of functions that you want to include in your application 16 | 17 | 18 |
19 | 20 | ## 💎The concept of package 21 | 22 | #### 🔷 In very simple language, a package in Python (Python Package) is a number of modules that are placed in a folder! Usually, the modules that are included in a package have a similar purpose. For example, the access level management part (authentication) of a program or user management can be a package. 23 | 24 |
25 | 26 | ## 💎The concept of library 27 | 28 | #### 🔷 In programming, a library is a collection of pre-written code that can be reused by other programs. A library typically contains a set of functions, routines, classes, or modules that can be called by an application to perform specific tasks, such as file I/O, network communication, data manipulation, and more. 29 | In Python, a library is typically packaged as a module or a set of modules that can be imported and used in a program. 30 | 31 |
32 | 33 | ## 💎The concept of framework 34 | 35 | #### 🔷 In Python, a framework is a collection of modules, libraries, and tools designed to help developers build applications more efficiently. A framework provides a set of conventions, best practices, and reusable code that can be used to simplify the development process and speed up the time-to-market of the application. 36 | Frameworks typically provide a foundation for building web applications, desktop applications, games, or other types of software. Some popular Python frameworks include Django, Flask, Pyramid, and CherryPy, among others. These frameworks provide a set of tools and libraries that help developers handle common tasks such as routing, database access, templating, security, and more. 37 | 38 | *** 39 | 40 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 41 | 42 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 43 | -------------------------------------------------------------------------------- /English language/Chapter Four/Operators/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹The topics we discuss in this chapter: 2 | 3 | - [Arithmetic operators](#-arithmetic-operators) 4 | - [comparison operators](#-comparison-operators) 5 | - [Assignment operators](#-assignment-operators) 6 | - [logical operators](#-logical-operators) 7 | - [membership operators](#-membership-operators) 8 | - [Identity operators](#-identity-operators) 9 | 10 | *** 11 | 12 | ## 💎Concept of Operators 13 | > Operators are used to perform operations on variables and values. 14 | 15 |
16 | 17 | ### 💢 Arithmetic operators 18 | > Arithmetic operators are used with numeric values to perform common mathematical operations 19 | 20 | ```python: 21 | x = 10 22 | y = 5 23 | 24 | print(x + y) # 15 25 | print(x - y) # 5 26 | print(x * y) # 50 27 | print(x / y) # 2.0 28 | print(x % y) # 0 29 | print(x ** y) # 100000 30 | print(x // y) # 2 31 | ``` 32 | 33 | *** 34 | 35 | ### 💢 comparison operators 36 | > Comparison operators are used to compare two values 37 | 38 | ```python: 39 | x = 10 40 | y = 5 41 | 42 | print(x == y) # False 43 | print(x != y) # True 44 | print(x > y) # True 45 | print(x < y) # False 46 | print(x >= y) # True 47 | print(x <= y) # False 48 | ``` 49 | 50 | *** 51 | 52 | ### 💢 Assignment operators 53 | > Assignment operators are used to assign values to variables 54 | 55 | ```python: 56 | x = 5 57 | x += 3 58 | print(x) # output: 8 59 | 60 | x = 5 61 | x -= 3 62 | print(x) # output: 2 63 | 64 | x = 5 65 | x *= 3 66 | print(x) # output: 15 67 | 68 | x = 6 69 | x /= 3 70 | print(x) # output: 2.0 71 | 72 | x = 7 73 | x %= 3 74 | print(x) # output: 1 75 | 76 | x = 7 77 | x //= 3 78 | print(x) # output: 2 79 | 80 | x = 2 81 | x **= 3 82 | print(x) # output: 8 83 | ``` 84 | 85 | *** 86 | 87 | ### 💢 logical operators 88 | > Logical operators are used to combine conditional statements 89 | 90 | ```python: 91 | x = 10 92 | y = 5 93 | 94 | print(x > 5 and y < 10) # True 95 | print(x > 5 or y > 10) # True 96 | print(not(x == y)) # True 97 | ``` 98 | 99 | *** 100 | 101 | ### 💢 membership operators 102 | > Membership operators are used to test if a sequence is presented in an object 103 | 104 | ```python: 105 | x = ["apple", "banana"] 106 | print("banana" in x) # True 107 | print("cherry" not in x) # True 108 | ``` 109 | 110 | *** 111 | 112 | ### 💢 Identity operators 113 | > Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location 114 | 115 | ```python: 116 | # is a comparison with the operator 117 | a = [1, 2, 3] 118 | b = a 119 | print(b is a) # Output: True 120 | 121 | c = [1, 2, 3] 122 | print(c is a) # Output: False 123 | 124 | # compares the absence with the not operator 125 | d = "Hello" 126 | e = "World" 127 | print(d is not e) # Output: True 128 | 129 | f = "Hello" 130 | print(d is not f) # Output: False 131 | ``` 132 | 133 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 134 | 135 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 136 | -------------------------------------------------------------------------------- /Persian language/Chapter Four/Operators/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹موضوعاتی که در این فصل مورد بحث قرار می‌دهیم: 2 | 3 | - [عملگرهای حسابی](#-عملگرهای-حسابی) 4 | - [عملگرهای مقایسه](#-عملگرهای-مقایسه) 5 | - [عملگرهای واگذاری](#-عملگرهای-واگذاری) 6 | - [عملگرهای منطقی](#-عملگرهای-منطقی) 7 | - [عملگرهای عضویت](#-عملگرهای-عضویت) 8 | - [عملگرهای هویت](#-عملگرهای-هویت) 9 | 10 | *** 11 | 12 | ## 💎مفهوم اپراتورها 13 | > عملگرها برای انجام عملیات روی متغیرها و مقادیر استفاده می شوند. 14 | 15 |
16 | 17 | ### 💢 عملگرهای حسابی 18 | > عملگرهای حسابی با مقادیر عددی برای انجام عملیات ریاضی رایج استفاده می شوند 19 | 20 | ```python: 21 | x = 10 22 | y = 5 23 | 24 | print(x + y) # 15 25 | print(x - y) # 5 26 | print(x * y) # 50 27 | print(x / y) # 2.0 28 | print(x % y) # 0 29 | print(x ** y) # 100000 30 | print(x // y) # 2 31 | ``` 32 | 33 | *** 34 | 35 | ### 💢 عملگرهای مقایسه 36 | > عملگرهای مقایسه برای مقایسه دو مقدار استفاده می شوند 37 | ```python: 38 | x = 10 39 | y = 5 40 | 41 | print(x == y) # False 42 | print(x != y) # True 43 | print(x > y) # True 44 | print(x < y) # False 45 | print(x >= y) # True 46 | print(x <= y) # False 47 | ``` 48 | 49 | *** 50 | 51 | ### 💢 عملگرهای واگذاری 52 | > عملگرهای انتساب برای تخصیص مقادیر به متغیرها استفاده می شوند 53 | 54 | ```python: 55 | x = 5 56 | x += 3 57 | print(x) # output: 8 58 | 59 | x = 5 60 | x -= 3 61 | print(x) # output: 2 62 | 63 | x = 5 64 | x *= 3 65 | print(x) # output: 15 66 | 67 | x = 6 68 | x /= 3 69 | print(x) # output: 2.0 70 | 71 | x = 7 72 | x %= 3 73 | print(x) # output: 1 74 | 75 | x = 7 76 | x //= 3 77 | print(x) # output: 2 78 | 79 | x = 2 80 | x **= 3 81 | print(x) # output: 8 82 | ``` 83 | 84 | *** 85 | 86 | ### 💢 عملگرهای منطقی 87 | > عملگرهای منطقی برای ترکیب عبارات شرطی استفاده می شوند 88 | 89 | ```python: 90 | x = 10 91 | y = 5 92 | 93 | print(x > 5 and y < 10) # True 94 | print(x > 5 or y > 10) # True 95 | print(not(x == y)) # True 96 | ``` 97 | 98 | *** 99 | 100 | ### 💢 عملگرهای عضویت 101 | > عملگرهای عضویت برای آزمایش اینکه آیا دنباله ای در یک شی ارائه شده است استفاده می شود 102 | 103 | ```python: 104 | x = ["apple", "banana"] 105 | print("banana" in x) # True 106 | print("cherry" not in x) # True 107 | ``` 108 | 109 | *** 110 | 111 | ### 💢 عملگرهای هویت 112 | > عملگرهای هویت برای مقایسه اشیاء استفاده می‌شوند، نه اگر برابر باشند، بلکه اگر در واقع یک شی با مکان حافظه یکسان باشند. 113 | 114 | ```python: 115 | # is a comparison with the operator 116 | a = [1, 2, 3] 117 | b = a 118 | print(b is a) # Output: True 119 | 120 | c = [1, 2, 3] 121 | print(c is a) # Output: False 122 | 123 | # compares the absence with the not operator 124 | d = "Hello" 125 | e = "World" 126 | print(d is not e) # Output: True 127 | 128 | f = "Hello" 129 | print(d is not f) # Output: False 130 | ``` 131 | 132 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 133 | 134 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 135 | -------------------------------------------------------------------------------- /English language/Chapter Seven/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹The topics we discuss in this chapter: 2 | 3 | - What Is Object-Oriented Programming in Python? 4 | - Class in Python 5 | 6 | 7 | ## 💎What Is Object-Oriented Programming in Python? 8 | 9 | ### 💢 Concept Object-Oriented Programming 10 | Object-oriented programming is a programming paradigm in which programs are designed and implemented as collections of objects. Each object has specific properties and behaviors that are defined as methods. By using object-oriented programming, you can design programs that are modular and extensible. In other words, by using objects and their relationships, you can design programs that are easily adaptable and changeable in the future.For example, suppose you want to design a program for managing a library. In object-oriented programming, a library object is defined with properties such as a name, address, opening and closing times, and behaviors such as adding books, deleting books, and searching for books. Similarly, a book object is defined with properties such as a name, author, and publication year, and behaviors such as displaying book information and editing book information. Then, using these objects, you can design your library program. 11 | 12 | ### 💢 Object-Oriented Programming in python 13 | Object-oriented programming is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects. 14 | 15 | For instance, an object could represent a person with properties like a name, age, and address and behaviors such as walking, talking, breathing, and running. Or it could represent an email with properties like a recipient list, subject, and body and behaviors like adding attachments and sending. 16 | 17 | Put another way, object-oriented programming is an approach for modeling concrete, real-world things, like cars, as well as relations between things, like companies and employees, students and teachers, and so on. OOP models real-world entities as software objects that have some data associated with them and can perform certain functions. 18 | 19 | Another common programming paradigm is procedural programming, which structures a program like a recipe in that it provides a set of steps, in the form of functions and code blocks, that flow sequentially in order to complete a task. 20 | 21 | The key takeaway is that objects are at the center of object-oriented programming in Python, not only representing the data, as in procedural programming, but in the overall structure of the program as well. 22 | 23 | 24 | ## 💎 Python Classes and Objects 25 | 26 | - Python is an object oriented programming language. 27 | - Almost everything in Python is an object, with its properties and methods. 28 | - A Class is like an object constructor, or a "blueprint" for creating objects. 29 | 30 | ### 💢 Create a Class: 31 | ```python: 32 | class MyClass: 33 | x = 5 34 | ``` 35 | 36 | ### 💢 Create Object: 37 | ```python: 38 | p1 = MyClass() 39 | print(p1.x) 40 | ``` 41 | 42 | ### 💢 The __init__() Function: 43 | > All classes have a function called __init__(), which is always executed when the class is being initiated. 44 | Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created: 45 | 46 | ```python: 47 | class Person: 48 | def __init__(self, name, age): 49 | self.name = name 50 | self.age = age 51 | 52 | p1 = Person("John", 36) 53 | 54 | print(p1.name) 55 | print(p1.age) 56 | ``` 57 | 58 | ### 💢 Object Methods 59 | > Objects can also contain methods. Methods in objects are functions that belong to the object. 60 | 61 | ```python: 62 | class Person: 63 | def __init__(self, name, age): 64 | self.name = name 65 | self.age = age 66 | 67 | def myfunc(self): 68 | print("Hello my name is " + self.name) 69 | 70 | p1 = Person("John", 36) 71 | p1.myfunc() 72 | ``` 73 | 74 | ### 💢 The self Parameter 75 | > The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. 76 | It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class: 77 | 78 | ```python: 79 | class Person: 80 | def __init__(mysillyobject, name, age): 81 | mysillyobject.name = name 82 | mysillyobject.age = age 83 | 84 | def myfunc(abc): 85 | print("Hello my name is " + abc.name) 86 | 87 | p1 = Person("John", 36) 88 | p1.myfunc() 89 | ``` 90 | 91 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 92 | 93 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 94 | -------------------------------------------------------------------------------- /Persian language/Chapter Five/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹موضوعاتی که در این فصل بحث می کنیم: 2 | 3 | - [دستورات شرطی (if, else, elif)](#مفهوم-دستورات-شرطی) 4 | - [حلقه ها در پایتون (for, while)](#مفهوم-حلقه-ها-در-پایتون) 5 | - [تابع ها در پایتون ](#مفهوم-توابع) 6 | 7 | *** 8 | 9 | ## 💎مفهوم دستورات شرطی 10 | > عبارات شرطی در پایتون به شما امکان می دهد کدی را مشخص کنید که باید طبق شرایط خاصی اجرا شود. یک دستور شرطی ممکن است یک شرط واحد یا ترکیبی از چند شرط باشد. 11 | 12 | ### ⭕️ پایتون از شرایط منطقی معمول ریاضیات پشتیبانی می کند: 13 | 14 | - برابر است با: a == b 15 | - برابر نیست: a != b 16 | - کمتر از: a < ب 17 | - کمتر یا مساوی با: a <= b 18 | - بزرگتر از: a > b 19 | - بزرگتر یا مساوی با: a >= b 20 | - این شرایط را می توان به روش های مختلفی مورد استفاده قرار داد، معمولاً در «عبارات if» و حلقه ها. 21 | 22 | ### 💢 استفاده از دستور if : 23 | > برای استفاده از دستور if از کلمه کلیدی if استفاده می‌کنیم 24 | 25 | Example: 26 | ```python: 27 | a = 33 28 | b = 200 29 | if b > a: 30 | print("b is greater than a") 31 | ``` 32 | Output : 33 | ```python: 34 | b is greater than a 35 | ``` 36 | 37 |
38 | 39 | 40 | ### 💢 دستور Elif : 41 | > کلمه کلیدی elif روشی است که پایتون می گوید: «اگر شرایط قبلی درست نبود، این شرط را امتحان کنید». 42 | 43 | Example: 44 | ```python: 45 | a = 33 46 | b = 33 47 | if b > a: 48 | print("b is greater than a") 49 | elif a == b: 50 | print("a and b are equal") 51 | ``` 52 | Output : 53 | ```python: 54 | a and b are equal 55 | ``` 56 | 57 |
58 | 59 | ### 💢 دستور Else : 60 | > کلمه کلیدی else هر چیزی را که تحت شرایط قبلی قرار نگرفته است را می گیرد. 61 | 62 | Example: 63 | ```python: 64 | a = 200 65 | b = 33 66 | if b > a: 67 | print("b is greater than a") 68 | elif a == b: 69 | print("a and b are equal") 70 | else: 71 | print("a is greater than b") 72 | ``` 73 | Output : 74 | ```python: 75 | a is greater than b 76 | ``` 77 | 78 | *** 79 | 80 | ## 💎مفهوم حلقه ها در پایتون 81 | > حلقه ها در پایتون یکی از ابزارهای اساسی و قدرتمندی هستند که برای تکرار بر روی یک بلوک کد به طور مکرر بر اساس شرایط خاص یا دنباله ای از داده ها استفاده می شود. دو نوع حلقه در پایتون وجود دارد 82 | 83 | ### 💢 حلقه For : 84 | > حلقه for زمانی استفاده می شود که بخواهیم روی یک دنباله (لیست، تاپل، رشته یا هر شیء قابل تکرار دیگری) تکرار کنیم و بلوک عبارات یا کد را برای هر عنصر دنباله اجرا کنیم. حلقه تا رسیدن به آخرین عنصر در دنباله ادامه می یابد. 85 | 86 | با حلقه for می‌توانیم مجموعه‌ای از دستورات را، یک بار برای هر آیتم در یک لیست، تاپل، مجموعه و غیره اجرا کنیم. 87 | 88 | Example: 89 | ```python: 90 | fruits = ["apple", "banana", "cherry"] 91 | for x in fruits: 92 | print(x) 93 | ``` 94 | Output : 95 | ```python: 96 | apple 97 | banana 98 | cherry 99 | ``` 100 | 101 | #### 🔶 دستور break 102 | > با دستور break می‌توانیم حلقه را قبل از اینکه تمام آیتم‌ها را حلقه کند متوقف کنیم: 103 | 104 | Example: 105 | ```python: 106 | fruits = ["apple", "banana", "cherry"] 107 | for x in fruits: 108 | print(x) 109 | if x == "banana": 110 | break 111 | ``` 112 | Output : 113 | ```python: 114 | apple 115 | banana 116 | ``` 117 | 118 | #### 🔶 تابع range(). 119 | > برای حلقه زدن مجموعه ای از کدها به تعداد مشخص، می توانیم از تابع range() استفاده کنیم. 120 | تابع range() دنباله‌ای از اعداد را برمی‌گرداند که به طور پیش‌فرض از 0 شروع می‌شود و به صورت پیش‌فرض 1 افزایش می‌یابد و به یک عدد مشخص ختم می‌شود. 121 | Example: 122 | 123 | ```python: 124 | for x in range(6): 125 | print(x) 126 | ``` 127 | Output : 128 | ```python: 129 | 0 130 | 1 131 | 2 132 | 3 133 | 4 134 | 5 135 | ``` 136 | 137 | #### 🔶 ه else در For Loop 138 | > کلمه کلیدی else در یک حلقه for، بلوکی از کد را مشخص می کند که باید پس از اتمام حلقه اجرا شود: 139 | 140 | Example: 141 | ```python: 142 | for x in range(6): 143 | print(x) 144 | else: 145 | print("Finally finished!") 146 | ``` 147 | Output : 148 | ```python: 149 | 0 150 | 1 151 | 2 152 | 3 153 | 4 154 | 5 155 | Finally finished! 156 | ``` 157 | 158 | ### 💢 حلقه while : 159 | > حلقه while زمانی استفاده می شود که بخواهیم یک دستور را در حالی که شرط داده شده درست است تکرار کنیم. حلقه تا زمانی که شرط نادرست شود ادامه می یابد. 160 | 161 | 162 | Example: 163 | ```python: 164 | i = 1 165 | while i < 6: 166 | print(i) 167 | i += 1 168 | ``` 169 | Output : 170 | ```python: 171 | 1 172 | 2 173 | 3 174 | 4 175 | 5 176 | ``` 177 | 178 | #### 🔶 دستور break 179 | > با دستور break می توانیم حلقه را متوقف کنیم حتی اگر شرط while درست باشد: 180 | 181 | Example: 182 | ```python: 183 | i = 1 184 | while i < 6: 185 | print(i) 186 | if i == 3: 187 | break 188 | i += 1 189 | ``` 190 | Output : 191 | ```python: 192 | 1 193 | 2 194 | 3 195 | ``` 196 | 197 | 198 | #### 🔶 ه Else در while Loop 199 | > با دستور else می‌توانیم یک بلوک کد را یکبار اجرا کنیم، زمانی که شرط دیگر درست نیست: 200 | 201 | Example: 202 | ```python: 203 | i = 1 204 | while i < 6: 205 | print(i) 206 | i += 1 207 | else: 208 | print("i is no longer less than 6") 209 | ``` 210 | Output : 211 | ```python: 212 | 1 213 | 2 214 | 3 215 | 4 216 | 5 217 | i is no longer less than 6 218 | ``` 219 | 220 | *** 221 | 222 | ## 💎مفهوم توابع 223 | > یک تابع یک بلوک از کد است که فقط زمانی اجرا می شود که فراخوانی شود. شما می توانید داده ها را که به عنوان پارامتر شناخته می شوند، به یک تابع منتقل کنید. یک تابع می تواند در نتیجه داده ها را برگرداند. 224 | 225 | Example: 226 | ```python: 227 | def my_function(): 228 | print("Hello from a function") 229 | ``` 230 | #### 🔶 فراخواندن یک تابع 231 | Example: 232 | ```python: 233 | def my_function(): 234 | print("Hello from a function") 235 | 236 | my_function() 237 | ``` 238 | Output : 239 | ```python: 240 | Hello from a function 241 | ``` 242 | 243 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 244 | 245 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 246 | -------------------------------------------------------------------------------- /English language/Chapter Five/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹The topics we discuss in this chapter: 2 | 3 | - [Conditional commands (if, else, elif)](#concept-of-conditional-commands) 4 | - [Loops in Python (for, while)](#concept-of-loops-in-python) 5 | - [Functions](#concept-of-functions) 6 | 7 | *** 8 | 9 | ## 💎Concept of Conditional commands 10 | > Conditional statements in Python allow you to specify code that should be executed according to certain conditions. A conditional statement may be a single condition or a combination of several conditions. 11 | 12 | ### ⭕️ Python supports the usual logical conditions from mathematics: 13 | 14 | - Equals: a == b 15 | - Not Equals: a != b 16 | - Less than: a < b 17 | - Less than or equal to: a <= b 18 | - Greater than: a > b 19 | - Greater than or equal to: a >= b 20 | - These conditions can be used in several ways, most commonly in "if statements" and loops. 21 | 22 | ### 💢 if statement : 23 | > An "if statement" is written by using the if keyword. 24 | 25 | Example: 26 | ```python: 27 | a = 33 28 | b = 200 29 | if b > a: 30 | print("b is greater than a") 31 | ``` 32 | Output : 33 | ```python: 34 | b is greater than a 35 | ``` 36 | 37 |
38 | 39 | 40 | ### 💢 Elif : 41 | > The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition" 42 | 43 | Example: 44 | ```python: 45 | a = 33 46 | b = 33 47 | if b > a: 48 | print("b is greater than a") 49 | elif a == b: 50 | print("a and b are equal") 51 | ``` 52 | Output : 53 | ```python: 54 | a and b are equal 55 | ``` 56 | 57 |
58 | 59 | ### 💢 Else : 60 | > The else keyword catches anything which isn't caught by the preceding conditions. 61 | 62 | Example: 63 | ```python: 64 | a = 200 65 | b = 33 66 | if b > a: 67 | print("b is greater than a") 68 | elif a == b: 69 | print("a and b are equal") 70 | else: 71 | print("a is greater than b") 72 | ``` 73 | Output : 74 | ```python: 75 | a is greater than b 76 | ``` 77 | 78 | *** 79 | 80 | ## 💎Concept of Loops in Python 81 | > Loops in Python are one of the basic and powerful tools used to iterate over a block of code repeatedly based on certain conditions or sequence of data. There are two types of loops in Python 82 | 83 | ### 💢 For Loops : 84 | > For loop is used when we want to iterate over a sequence (list, tuple, string, or any other iterable object) and execute the block of statements or code for each element of the sequence. The loop continues till the last element in the sequence is reached. 85 | 86 | With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. 87 | 88 | Example: 89 | ```python: 90 | fruits = ["apple", "banana", "cherry"] 91 | for x in fruits: 92 | print(x) 93 | ``` 94 | Output : 95 | ```python: 96 | apple 97 | banana 98 | cherry 99 | ``` 100 | 101 | #### 🔶 The break Statement 102 | > With the break statement we can stop the loop before it has looped through all the items: 103 | 104 | Example: 105 | ```python: 106 | fruits = ["apple", "banana", "cherry"] 107 | for x in fruits: 108 | print(x) 109 | if x == "banana": 110 | break 111 | ``` 112 | Output : 113 | ```python: 114 | apple 115 | banana 116 | ``` 117 | 118 | #### 🔶 The range() Function 119 | > To loop through a set of code a specified number of times, we can use the range() function, 120 | The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. 121 | Example: 122 | 123 | ```python: 124 | for x in range(6): 125 | print(x) 126 | ``` 127 | Output : 128 | ```python: 129 | 0 130 | 1 131 | 2 132 | 3 133 | 4 134 | 5 135 | ``` 136 | 137 | #### 🔶 Else in For Loop 138 | > The else keyword in a for loop specifies a block of code to be executed when the loop is finished: 139 | 140 | Example: 141 | ```python: 142 | for x in range(6): 143 | print(x) 144 | else: 145 | print("Finally finished!") 146 | ``` 147 | Output : 148 | ```python: 149 | 0 150 | 1 151 | 2 152 | 3 153 | 4 154 | 5 155 | Finally finished! 156 | ``` 157 | 158 | ### 💢 The while Loop : 159 | > While loop is used when we want to repeat a statement while the given condition is true. The loop continues till the condition becomes false. 160 | 161 | 162 | Example: 163 | ```python: 164 | i = 1 165 | while i < 6: 166 | print(i) 167 | i += 1 168 | ``` 169 | Output : 170 | ```python: 171 | 1 172 | 2 173 | 3 174 | 4 175 | 5 176 | ``` 177 | 178 | #### 🔶 The break Statement 179 | > With the break statement we can stop the loop even if the while condition is true: 180 | 181 | Example: 182 | ```python: 183 | i = 1 184 | while i < 6: 185 | print(i) 186 | if i == 3: 187 | break 188 | i += 1 189 | ``` 190 | Output : 191 | ```python: 192 | 1 193 | 2 194 | 3 195 | ``` 196 | 197 | 198 | #### 🔶 Else in For Loop 199 | > With the else statement we can run a block of code once when the condition no longer is true: 200 | 201 | Example: 202 | ```python: 203 | i = 1 204 | while i < 6: 205 | print(i) 206 | i += 1 207 | else: 208 | print("i is no longer less than 6") 209 | ``` 210 | Output : 211 | ```python: 212 | 1 213 | 2 214 | 3 215 | 4 216 | 5 217 | i is no longer less than 6 218 | ``` 219 | 220 | *** 221 | 222 | ## 💎Concept of Functions 223 | > A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function. A function can return data as a result. 224 | 225 | Example: 226 | ```python: 227 | def my_function(): 228 | print("Hello from a function") 229 | ``` 230 | #### 🔶 Calling a Function 231 | Example: 232 | ```python: 233 | def my_function(): 234 | print("Hello from a function") 235 | 236 | my_function() 237 | ``` 238 | Output : 239 | ```python: 240 | Hello from a function 241 | ``` 242 | 243 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 244 | 245 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 246 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![Alt text](src/F3.png) 3 | 4 |

"Programming is a different perspective and lifestyle"

5 |

"برنامه نویسی یک دیدگاه و سبک زندگی متفاوت است"

6 | 7 | *** 8 | 9 |

💢 An introduction to the Python programming language 💢

10 |

💢 مقدمه ای بر زبان برنامه نویسی پایتون 💢

11 | 12 | #### 🔷 What exactly is going on here? 13 | > Python is one of the most popular programming languages, which is very attractive and useful for programmers and those interested in this field due to its simplicity and high power. Using Python, one can easily develop applications, websites, games, and many other projects. 14 | Here, we try to give you a complete introduction to the Python language, so that you can easily understand the various concepts of this field and not face any problems in the learning process. 15 | This repository can always be by your side as a cheat sheet for help and guidance in Python and programming projects. 16 | 17 | This repository is written in [Persian](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language) and [English](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language) languages, you can access the contents by choosing either of them. 18 | 19 | #### 🔷 دقیقا اینجا چه خبره؟ 20 | > پایتون یکی از محبوب‌ترین زبان‌های برنامه‌نویسی است که به دلیل سادگی و قدرت بالایش، برای برنامه‌نویسان و علاقه‌مندان به این حوزه بسیار جذاب و مفید است. با استفاده از پایتون، می‌توان به راحتی، برنامه‌های کاربردی، وب‌سایت‌ها، بازی‌ها، و بسیاری از پروژه‌های دیگر را توسعه داد. 21 | در اینجا، سعی می‌کنیم مقدمه‌ای کامل از زبان پایتون را به شما ارائه دهیم، تا بتوانید به راحتی مفاهیم مختلف این حوزه را درک کنید و در فرایند آموزش با مشکل مواجه نشوید. 22 | این ریپازیتوری، می‌تواند همیشه در کنار شما به عنوان یک برگه تقلب، برای کمک و راهنمایی در انجام پروژه‌های پایتون و برنامه‌نویسی، قرار بگیرد. 23 | 24 | این ریپازیتوری به دو زبان [فارسی](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language) و [انگلیسی](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language) نوشته شده است که شما میتوانید با انتخاب هر کدام از آن ها به محتویات دسترسی داشته باشید 25 | 26 | 27 | *** 28 | 29 |

♨️ List of chapters provided ♨️

30 |

♨️ فهرست فصل های ارائه شده ♨️

31 |
32 | 33 | 34 | - Chapter One [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20One) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20One) 35 | 36 | - 🌀 What is programming? 37 | - 🌀 High, low and intermediate programming language 38 | - 🌀 General purpose and special purpose languages 39 | - 🌀 Interpreted and compiler languages 40 | - 🌀 Static, dynamic, strong and weak typing languages 41 | - 🌀 Programming paradigms 42 | - 🌀 The story of Python (History) 43 | - 🌀 Applications of Python 44 | - 🌀 What is the algorithm? 45 | - 🌀 What is a flowchart? 46 | 47 | - Chapter Two [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Two) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20Two) 48 | 49 | - 🌀 Concept of IDE & text editor 50 | - 🌀 Install python 51 | 52 | - Chapter Three [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Three) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20Three) 53 | 54 | - 🌀 Concept of Variable 55 | - 🌀 Python Data Types 56 | 57 | - string 58 | - integers 59 | - bool 60 | - float 61 | - Data Structures(List, Tuple, Dictionaries, set) 62 | 63 | - 🌀 Convert data types to each other 64 | 65 | - Chapter Four [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Four/Operators) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20Four/Operators) 66 | 67 | 68 | - 🌀 Arithmetic operators 69 | - 🌀 comparison operators 70 | - 🌀 Assignment operators 71 | - 🌀 logical operators 72 | - 🌀 membership operators 73 | - 🌀 Identity operators 74 | 75 | - Chapter Five [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Five) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20Five) 76 | 77 | 78 | - 🌀 Conditional commands (if, else, elif) 79 | - 🌀 Loops in Python (for, while) 80 | - 🌀 Functions 81 | 82 | - Chapter Six [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Six) [(Persian language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/Persian%20language/Chapter%20Six) 83 | 84 | 85 | - 🌀 Libraries in Python (The concept of script, module, package, library and framework) 86 | 87 | - Chapter Seven [(English language)](https://github.com/graymicro/introduction-to-the-Python-programming-language/tree/master/English%20language/Chapter%20Seven) 88 | 89 | - 🌀 What Is Object-Oriented Programming in Python? 90 | - 🌀 Class in Python 91 | 92 | *** 93 | 94 |

💣 Support this repository 💣

95 |
96 | 97 | - By giving this repository a star(⭐️), you made it more visible 98 | - Be sure to send this repository to your friends who are interested in this area 99 | - Follow the gray cube team on other platforms 100 | 101 | *** 102 | ### 📚 Resources used 103 | 104 | - https://realpython.com/ 105 | - https://www.w3schools.com/ 106 | - https://www.python.org/ 107 | 108 | 109 | *** 110 | 111 |

💣 حمایت از این ریپازیتوری 💣

112 |
113 | 114 | - با دادن یک ستاره(⭐️) به این ریپازیتوری باعث بیشتر دیده تر شدن شدید 115 | - حتما برای دوستانتون که علاقه به این حوضه دارند این ریپازیتوری رو ارسال کنید 116 | - تیم مکعب خاکستری رو در بقیه [پلتفرم ها](https://graycubeteam.github.io/) دنبال کنید 117 | 118 | *** 119 | ### 📚 منابع استفاده شده 120 | - https://realpython.com/ 121 | - https://www.w3schools.com/ 122 | - https://www.python.org/ 123 | 124 | *** 125 | 126 | -------------------------------------------------------------------------------- /English language/Chapter Two/README.md: -------------------------------------------------------------------------------- 1 | ## ⭕️ The topics we discuss in this chapter: 2 | 3 | - [Concept of IDE & text editor](#concept-of-ide--text-editor) 4 | - [Install Python](#-how-to-install-python) 5 | 6 | 7 | 8 | # 💎Concept of IDE & Text Editor 9 | > IDE and Text Editors are programs that developers use to write, edit, and manage programs and provide them with various features. 10 | However, there are differences between the two, which we will discuss below 11 | 12 | ### **Concept IDE** => 13 | - An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE typically consists of a source code editor, build automation tools, and a debugger. It can also include features like version control integration, graphical user interface (GUI) builders, and many other tools that help simplify and automate the software development process. 14 | 15 | ### **Concept Text Editor** => 16 | - A text editor is a software application used for editing plain text files. Unlike an IDE, a text editor does not have any built-in features for compiling or debugging code. Text editors are used mainly by developers who prefer lightweight, customizable tools for writing code. Some popular text editors include Atom, Sublime Text, and Visual Studio Code. 17 | 18 | --- 19 | ##### 🔹While both IDEs and text editors can be used for writing code, the main difference between them is that IDEs provide a more comprehensive set of tools designed specifically for software development, while text editors offer a more minimalistic approach with fewer built-in features. Ultimately, the choice between using an IDE or a text editor comes down to personal preference and the specific needs of the developer. 20 | --- 21 | 22 |
23 | 24 | ![Alt text](../../src/ProgrammingEditors.jpg) 25 | 26 |
27 | 28 | ## 💢The difference between IDE and text editor 29 | 30 | 1. IDE (Integrated Development Environment) is an integrated development environment that includes tools such as coding, debugging, compiling, and testing. These tools are automatically synchronized with each other and help programmers quickly build complex programs. 31 | 32 | 2. Text Editor is a program used for editing and writing programming code. These tools typically only have text editing capabilities and do not have any other tools such as debuggers, compilers, and testers. 33 | 34 | 3. IDEs are typically used for complex and large projects, while Text Editors are used for smaller and simpler projects. 35 | 36 | 4. IDEs have the ability to detect code errors and help programmers run the program better and faster, while Text Editors do not have this capability. 37 | 38 | 5. IDEs are usually designed for specific programming languages such as Java, C++, and Python, while Text Editors can be used for all programming languages. 39 | 40 | *** 41 | 42 |
43 | 44 | # 🐍 How to Install Python 45 | > In this article, we will teach you how to install Python on Windows. Unlike other operating systems such as Mac OS and Linux, the Python programming language is not installed by default on the Windows operating system. However, this does not mean that this programming language will not be useful for Windows users or that Windows users will not be able to program their own applications using this language. 46 | 47 | ## Step 1 — Downloading the Python Installer 48 | 1. Go to the official Python download page for Windows. 49 | 50 | 2. Find a stable Python 3 release. This tutorial was tested with Python version 3.10.10. 51 | 52 | 3. Click the appropriate link for your system to download the executable file: Windows installer (64-bit) or Windows installer (32-bit). 53 | 54 | ![Alt text](../../src/1.png) 55 | 56 | ## Step 2 — Running the Executable Installer 57 | 1. After the installer is downloaded, double-click the .exe file, for example python-3.10.10-amd64.exe, to run the Python installer. 58 | 59 | 2. Select the Install launcher for all users checkbox, which enables all users of the computer to access the Python launcher application. 60 | 61 | 3. Select the Add python.exe to PATH checkbox, which enables users to launch Python from the command line. 62 | 63 | ![Alt text](../../src/2.png) 64 | 65 | 4. If you’re just getting started with Python and you want to install it with default features as described in the dialog, then click Install Now and go to Step 4 - Verify the Python Installation. To install other optional and advanced features, click Customize installation and continue. 66 | 67 | 5. The Optional Features include common tools and resources for Python and you can install all of them, even if you don’t plan to use them. 68 | 69 | ![Alt text](../../src/3.png) 70 | 71 | **Select some or all of the following options:** 72 | 73 | - Documentation: recommended 74 | - pip: recommended if you want to install other Python packages, such as NumPy or pandas 75 | - tcl/tk and IDLE: recommended if you plan to use IDLE or follow tutorials that use it 76 | - Python test suite: recommended for testing and learning 77 | - py launcher and for all users: recommended to enable users to launch Python from the command line 78 | 79 | 6. Click Next. 80 | 7. The Advanced Options dialog displays. 81 | 82 | ![Alt text](../../src/4.png) 83 | 84 | **Select the options that suit your requirements:** 85 | 86 | - Install for all users: recommended if you’re not the only user on this computer 87 | - Associate files with Python: recommended, because this option associates all the Python file types with the launcher or editor 88 | - Create shortcuts for installed applications: recommended to enable shortcuts for Python applications 89 | - Add Python to environment variables: recommended to enable launching Python 90 | - Precompile standard library: not required, it might down the installation 91 | - Download debugging symbols and Download debug binaries: recommended only if you plan to create C or C++ extensions 92 | - Make note of the Python installation directory in case you need to reference it later. 93 | 94 | 8. Click Install to start the installation. 95 | 9. After the installation is complete, a Setup was successful message displays. 96 | 97 | ![Alt text](../../src/5.png) 98 | 99 | Step 3 — Verify the Python Installation 100 | You can verify whether the Python installation is successful either through the command line or through the Integrated Development Environment (IDLE) application, if you chose to install it. 101 | 102 | Go to Start and enter cmd in the search bar. Click Command Prompt. 103 | 104 | Enter the following command in the command prompt: 105 | ``` 106 | python --version 107 | ``` 108 | An example of the output is: 109 | ``` 110 | Output 111 | Python 3.10.10 112 | ``` 113 | 114 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 115 | [graycubeteam.github.io](graycubeteam.github.io) 116 | **license by gray cube team** 117 | -------------------------------------------------------------------------------- /Persian language/Chapter Two/README.md: -------------------------------------------------------------------------------- 1 | ## ⭕️ موضوعاتی که در این فصل مورد بحث قرار می‌دهیم: 2 | 3 | - [مفهوم IDE و ویرایشگر متن](#مفهوم-ide-و-ویرایشگر-متن) 4 | - [نصب زبان برنامه نویسی پایتون](#-نحوه-نصب-پایتون) 5 | 6 |
7 | 8 | 9 | # 💎مفهوم IDE و ویرایشگر متن 10 | > یک IDE و Text Editor برنامه هایی هستند که توسعه دهندگان برای نوشتن، ویرایش و مدیریت برنامه ها از آن ها استفاده می‌کنند و امکانات های مختلفی را برای آن ها فراهم می‌کنند 11 | اما با این حال تفاوت هایی بین این دو وجود دارد که در ادامه آن ها را برسی می‌کنیم 12 | 13 | ### **مفهوم IDE** => 14 | - محیط توسعه یکپارچه (IDE) یک نرم افزار کاربردی است که امکانات جامعی را برای برنامه نویسان کامپیوتر برای توسعه نرم افزار فراهم می کند. یک IDE معمولاً از یک ویرایشگر کد منبع، ابزارهای اتوماسیون ساخت و یک دیباگر تشکیل شده است. همچنین می‌تواند شامل ویژگی‌هایی مانند یکپارچه‌سازی کنترل نسخه، سازندگان رابط کاربری گرافیکی (GUI) و بسیاری از ابزارهای دیگر باشد که به ساده‌سازی و خودکارسازی فرآیند توسعه نرم‌افزار کمک می‌کنند. 15 | 16 | ### **مفهوم Text Editor** => 17 | - ویرایشگر متن نرم افزاری است که برای ویرایش فایل های متنی ساده استفاده می شود. برخلاف IDE، یک ویرایشگر متن هیچ ویژگی داخلی برای کامپایل یا اشکال زدایی کد ندارد. ویرایشگرهای متن عمدتاً توسط توسعه دهندگانی استفاده می شود که ابزارهای سبک وزن و قابل تنظیم را برای نوشتن کد ترجیح می دهند. برخی از ویرایشگرهای متن محبوب عبارتند از Atom، Sublime Text و Visual Studio Code. 18 | 19 | --- 20 | ##### 🔹در حالی که هر دو IDE و ویرایشگر متن را می توان برای نوشتن کد استفاده کرد، تفاوت اصلی بین آنها این است که IDE ها مجموعه جامع تری از ابزارها را ارائه می دهند که به طور خاص برای توسعه نرم افزار طراحی شده اند، در حالی که ویرایشگرهای متن رویکرد حداقلی تری را با ویژگی های داخلی کمتر ارائه می دهند. در نهایت، انتخاب بین استفاده از یک IDE یا یک ویرایشگر متن به اولویت شخصی و نیازهای خاص توسعه دهنده بستگی دارد. 21 | --- 22 | 23 |
24 | 25 | ![Alt text](../../src/ProgrammingEditors.jpg) 26 | 27 |
28 | 29 | ## 💢 تفاوت بین IDE و ویرایشگر متن 30 | 31 | 1️⃣ محیط توسعه یکپارچه (IDE) یک محیط توسعه یکپارچه است که شامل ابزارهایی مانند کدنویسی، اشکال زدایی، کامپایل و آزمایش است. این ابزارها به طور خودکار با یکدیگر همگام می شوند و به برنامه نویسان کمک می کنند تا به سرعت برنامه های پیچیده بسازند. 32 | 33 | 2️⃣ ویراشگر متن برنامه ای است که برای ویرایش و نوشتن کدهای برنامه نویسی استفاده می شود. این ابزارها معمولاً فقط دارای قابلیت ویرایش متن هستند و هیچ ابزار دیگری مانند دیباگرها، کامپایلرها و تسترها ندارند. 34 | 35 | 3️⃣ محیط توسعه یکپارچه (IDE) ها معمولا برای پروژه های پیچیده و بزرگ استفاده می شوند، در حالی که ویرایشگرهای متن برای پروژه های کوچکتر و ساده تر استفاده می شوند. 36 | 37 | 4️⃣ محیط توسعه یکپارچه (IDE) ها توانایی تشخیص خطاهای کد را دارند و به برنامه نویسان کمک می کنند تا برنامه را بهتر و سریعتر اجرا کنند، در حالی که ویرایشگرهای متن این قابلیت را ندارند. 38 | 39 | 5️⃣ محیط توسعه یکپارچه (IDE) ها معمولا برای زبان های برنامه نویسی خاص مانند جاوا، سی پلاس پلاس و پایتون طراحی می شوند، در حالی که ویرایشگرهای متن را می توان برای همه زبان های برنامه نویسی استفاده کرد.. 40 | 41 | *** 42 | 43 |
44 | 45 | # 🐍 نحوه نصب پایتون 46 | > در این مقاله نحوه نصب پایتون در ویندوز را به شما آموزش می دهیم. زبان برنامه نویسی پایتون بر خلاف سایر سیستم عامل ها مانند سیستم عامل مک و لینوکس به طور پیش فرض روی سیستم عامل ویندوز نصب نیست. با این حال، این بدان معنا نیست که این زبان برنامه نویسی برای کاربران ویندوز مفید نخواهد بود یا کاربران ویندوز نمی توانند برنامه های کاربردی خود را با استفاده از این زبان برنامه های خود را توسعه دهند. 47 | 48 | ## مرحله 1 - دانلود نصب کننده پایتون 49 | 1️⃣ به صفحه رسمی دانلود پایتون برای ویندوز بروید. 50 | 51 | 2️⃣ نسخه پایدار پایتون 3 را پیدا کنید. این آموزش با نسخه 3.10.10 پایتون تست شده است. 52 | 53 | 3️⃣ برای دانلود فایل اجرایی روی لینک مناسب برای سیستم خود کلیک کنید: Windows installer (64 بیتی) یا Windows installer (32 بیت). 54 | 55 | ![Alt text](../../src/1.png) 56 | 57 | ## مرحله 2 - اجرای نصب کننده اجرایی 58 | 1️⃣ پس از دانلود نصب کننده، روی فایل .exe، به عنوان مثال python-3.10.10-amd64.exe، دوبار کلیک کنید تا نصب کننده پایتون اجرا شود. 59 | 60 | 2️⃣ چک باکس Install launcher for all users را انتخاب کنید، که همه کاربران رایانه را قادر می سازد به برنامه راه اندازی پایتون دسترسی داشته باشند. 61 | 62 | 3️⃣ چک باکس Add python.exe to PATH را انتخاب کنید که به کاربران امکان می دهد پایتون را از خط فرمان راه اندازی کنند. 63 | 64 | ![Alt text](../../src/2.png) 65 | 66 | 4️⃣ اگر به تازگی با پایتون شروع کرده اید و می خواهید آن را با ویژگی های پیش فرض همانطور که در گفتگو توضیح داده شده است نصب کنید، روی Install Now کلیک کنید و به مرحله 4 بروید - تأیید نصب پایتون. برای نصب سایر ویژگی های اختیاری و پیشرفته، روی Customize install کلیک کرده و ادامه دهید. 67 | 68 | 5️⃣ویژگی های اختیاری شامل ابزارها و منابع رایج برای پایتون است و می توانید همه آنها را نصب کنید، حتی اگر قصد استفاده از آنها را ندارید. 69 | 70 | ![Alt text](../../src/3.png) 71 | 72 | **برخی یا همه گزینه های زیر را انتخاب کنید:** 73 | 74 | - Documentation: recommended 75 | - pip: recommended if you want to install other Python packages, such as NumPy or pandas 76 | - tcl/tk and IDLE: recommended if you plan to use IDLE or follow tutorials that use it 77 | - Python test suite: recommended for testing and learning 78 | - py launcher and for all users: recommended to enable users to launch Python from the command line 79 | 80 | 6️⃣ روی Next کلیک کنید. 81 | 82 | 7️⃣ گفتگوی گزینه های پیشرفته نمایش داده می شود. 83 | 84 | ![Alt text](../../src/4.png) 85 | 86 | **گزینه های متناسب با نیاز خود را انتخاب کنید:** 87 | 88 | - Install for all users: recommended if you’re not the only user on this computer 89 | - Associate files with Python: recommended, because this option associates all the Python file types with the launcher or editor 90 | - Create shortcuts for installed applications: recommended to enable shortcuts for Python applications 91 | - Add Python to environment variables: recommended to enable launching Python 92 | - Precompile standard library: not required, it might down the installation 93 | - Download debugging symbols and Download debug binaries: recommended only if you plan to create C or C++ extensions 94 | - Make note of the Python installation directory in case you need to reference it later. 95 | 96 | 8️⃣ برای شروع نصب روی Install کلیک کنید. 97 | 8️⃣ پس از اتمام نصب، پیام Setup was موفقیت آمیز نمایش داده می شود. 98 | 99 | ![Alt text](../../src/5.png) 100 | 101 | مرحله 3 - نصب پایتون را تأیید کنید 102 | اگر نصب پایتون را انتخاب کردید، می توانید از طریق خط فرمان یا از طریق برنامه محیط توسعه مجتمع (IDLE) موفقیت آمیز بودن نصب پایتون را تأیید کنید. 103 | 104 | به Start رفته و cmd را در نوار جستجو وارد کنید. روی Command Prompt کلیک کنید. 105 | 106 | دستور زیر را در خط فرمان وارد کنید: 107 | ``` 108 | python --version 109 | ``` 110 | نمونه ای از خروجی این است: 111 | ``` 112 | Output 113 | Python 3.10.10 114 | ``` 115 | 116 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 117 | [graycubeteam.github.io](graycubeteam.github.io) 118 | **license by gray cube team** 119 | -------------------------------------------------------------------------------- /Persian language/Chapter One/README.md: -------------------------------------------------------------------------------- 1 | 2 | # **💢 مقدمه ای برای شروع 💢** 3 | > در این قسمت قصد داریم به مباحثی بپردازیم که قبل از شروع برنامه نویسی باید آنها را درک کنید تا در ادامه با مشکل مواجه نشوید. 4 | 5 |
6 | 7 | ## 🔹موضوعاتی که در این فصل مورد بحث قرار می‌دهیم: 8 | 9 | - [برنامه نویسی چیست؟](#-برنامه-نویسی-چیست) 10 | - [زبان برنامه نویسی سطح بالا، پایین و متوسط](#-زبان-برنامه-نویسی-بالا-پایین-و-متوسط) 11 | - [زبان های چند منظوره و خاص مظوره](#-زبان-های-هدف-عمومی-و-هدف-خاص) 12 | - [زبان های مفسری و کامپایلری](#-زبانهای-تفسیر-شده-و-کامپایلر) 13 | - [زبان های ایستا، پویا، قوی و ضعیف](#-زبان-های-تایپ-ایستا-پویا-قوی-و-ضعیف) 14 | - [پارادایم های برنامه نویسی](#-پارادایم-های-برنامه-نویسی) 15 | - [داستان پایتون (تاریخچه)](#-داستان-پایتون-تاریخچه) 16 | - [کاربردهای پایتون](#-کاربردهای-پایتون) 17 | - [الگوریتم چیست؟](#-الگوریتم-چیست) 18 | - [فلوچارت چیست؟](#-فلوچارت-چیست) 19 | 20 |
21 | 22 | ## 🔰 برنامه نویسی چیست؟ 23 | > برنامه نویسی فرآ یند نوشتن کد(متن) برای ساختن نرم افزارها، برنامه ها، وبسایت ها و اپلیکیشن های موبایل 24 | است. به طور کلی، برنامه نویسان با استفاده از یک زبان برنامه نویسی، دستورالعمل هایی برای کامپیوتر ایجاد 25 | می کنند تا برنامه ی مورد نظر را ایجاد کنند(با کامپیوتر صحبت می کنند). این دستورالعمل ها ممکن است شامل 26 | محاسبات ریاضی، داده پردازی ، مدیریت فایل، شبکه و بسیار ی از سایر عملیات باشن 27 | 28 |
29 | 30 | ## 💠 زبان برنامه نویسی سطح بالا، پایین و متوسط 31 | زبان برنامه نویسی سطح بالا: 32 | این زبان ها برای توسعه ی برنامه هایی با پی چیدگی های مختلف طراحی شده اند و درک و نوشتن آنها برای 33 | برنامه نویسان آسان است. زبانها ی سطح بالا معمولا برای توسعه ی برنامه های وب، نرمافزارها ی دسکتاپ و 34 | بازی های رایانه ای استفاده می شوند. به عنوان مثال: جاوا، پایتون، سی شارپ، جاوااسکریپت و... 35 | گفتاری نزدیک به زبان انسان دارند 36 | 37 | زبان برنامه نویسی سطح پایین: 38 | این زبان ها برای کنترل دقیق تر و بهره وری بیشتر در سیستم های کامپیوتری طراحی شده اند. زبان های سطح پایین 39 | مستقیما با سخت افزار و معماری کامپیوتر سازگار هستند و به عنوان نمونه می توان به زبان های ماشینی و زبان های نزدیک به آنها مانند زبان اسمبلی اشاره کرد. 40 | گفتار آنها شبیه زبان انسان نیست و به زبان 0 و 1 (زبان کامپیوتر) نزدیک تر است 41 | 42 | زبان برنامه نویسی سطح متوسط: 43 | این زبان ها بین دو دسته بندی قبلی قرار می‌گیرند و معمولا برای توسعه ی نرم افزارهایی با پیچیدگی زیاد استفاده می شوند. مانند : C++,C 44 | این زبان ها گفتاری بین زبان انسان و زبان کامپیوتر دارند 45 |
46 | 47 | ## 💠 زبان های چند منظوره و خاص منظوره 48 | زبان های کامپیوتری را می توان به دو دسته تقسیم کرد: چند منظوره و خاص منظوره : 49 | 50 | زبان های چند منظوره: 51 | از این زبان ها برای حل بسیاری از مسائل استفاده می شود و برای برنامه نویسی انواع برنامه ها اعم از برنامه های کاربردی، سیستمی، وب و ... استفاده می شود به عبارت دیگر زبان های عمومی توانایی حل مسائل مختلف را دارند و می توان از آنها برای کاربردهای مختلف استفاده کرد. چند نمونه از 52 | زبان های رایج عبارتند از جاوا، پایتون، سی پلاس پلاس و سی شارپ. 53 | اما آنها در همه زمینه ها عالی نیستند و شاید فقط در یک زمینه عالی باشند 54 | 55 | 56 | زبان خاص منظوره: 57 | این زبان ها برای حل مسائل خاص و محدودتر طراحی شده اند و بیشتر در زمینه هایی مانند علوم شناختی، تصویر استفاده می شوند. 58 | پردازش، مهندسی نرم افزار، طراحی وب سایت، پردازش زبان طبیعی و ... در 59 | به عبارت دیگر، زبان های خاصی برای این برنامه ها به دلیل وجود آنها انتخاب می شوند 60 | قابلیت تنظیم بیشتر و تعریف دقیق تر برای مشکلات خاص. چند نمونه از 61 | زبان های خاص عبارتند از MATLAB، R، SQL، HTML و CSS. 62 | این زبان ها فقط در زمینه تخصصی خود قابل استفاده هستند 63 | 64 | _به طور خلاصه، زبان های چند منظوره برای حل طیف وسیع تری از مسائل طراحی شده اند، در عین حال زبان های خاص منظوره برای حل مشکلات خاص تر و محدودتر طراحی شده اند._ 65 | 66 |
67 | 68 | ## 💠 زبانهای مفسری و کامپایلری 69 | زبان های برنامه نویسی به دو دسته کلی «کامپایلری» و «زبان های مفسری» تقسیم می شوند. 70 | 71 | زبان های کامپایل شده، از طریق یک برنامه کامپیوتری به نام کامپایلر، کد نوشته شده را تبدیل می‌کند به زبان کامپیوتر که قابل فهم برای کامپیوتر شود. زمانی که کامپایلر کد نوشته شده را به کد اجرایی( 0-1 ) تبدیل می کند، تمام اجزای آن را به طور کامل تفسیر(بازبینی) می کند و اگر کد نوشته شده مشکلی نداشته باشد یک فایل خروجی به ما تحویل می‌دهد و دیگر نیاز نیست که برای هر بار اجرا دوباره کد نوشته شده کامپایل شود مگر آنکه نیاز به تغییر در کد نوشته شده باشد زبان هایی 72 | مانند C، C++، Fortran و Pascal نمونه هایی از زبان های کامپایلری شده هستند. 73 | 74 | 75 | زبان های تفسیر شده کد منبع را به صورت تفسیری (یعنی خط به خط) اجرا می کنند یعنی نیاز است برای هربار اجرای کد نوشته شده مفسر از اول برنامه کد را خط به خط اجرا کند. پایتون، روبی و جاوا اسکریپت نمونه هایی از زبان های تفسیر شده هستند. برای همین سرعت زبان های مفسری کم تر از کامپایلری است 76 | 77 |
78 | 79 | ## 💠 زبان های مدل ایستا، پویا، قوی و ضعیف: 80 | زبان های برنامه نویسی از نظر مدل به چهار دسته تقسیم می شوند: 81 | 82 | نوع تایپ استاتیک: 83 | در این نوع زبان برنامه نویسی، نوع متغیرها در کامپایل مشخص می شود 84 | زمان و کامپایلر قبل از اجرای کدی که هر نوع داده ای استفاده می کند، چک می کند 85 | با نوع تعریف شده مطابقت دارد. 86 | مزیت اصلی استفاده از این نوع زبان برنامه نویسی افزایش قابلیت اطمینان برای 87 | برنامه های بزرگ و پیچیده 88 | مثال: جاوا، سی پلاس پلاس، سی شارپ 89 | 90 | 91 | تایپ پویا: 92 | این نوع نوشتن، مقادیر و انواع متغیرها در زمان اجرا به جای آن بررسی می شوند 93 | تلفیقی. با این حال، این نوع زبان برنامه نویسی در کوچک و بسیار گسترده است 94 | کاربردهای ساده ای دارد و در زبان های برنامه نویسی مانند پایتون بسیار مورد استفاده قرار می گیرد. 95 | مثال: پایتون، روبی، جاوا اسکریپت 96 | 97 | تایپ قوی: 98 | در این نوع زبان برنامه نویسی محدودیتی برای پذیرش نداریم 99 | محدودیت ها، تغییر نوع متغیر تنها زمانی امکان پذیر است که به صورت منطقی مدیریت شود 100 | و معمولاً نیاز به تغییر متغیر دارد، اما در موارد دیگر کاملاً تغییر می کند 101 | اجتناب کرد. 102 | مثال: جاوا، سی پلاس پلاس، سی شارپ 103 | 104 | تایپ ضعیف: 105 | این نوع نوشتار شبیه به نوع نوشتار پویا است با این تفاوت که در اینجا 106 | تبدیل نوع داده با دسترسی آسان و بدون بررسی قوانین انجام می شود. بعد از 107 | با تأیید نوع داده، نوع آن به طور خودکار با توجه به نوع عملیات تعیین می شود. 108 | مثال: PHP، Perl، JavaScript. 109 | 110 |
111 | 112 | ## 💠 پارادایم های برنامه نویسی: 113 | _برنامه نویسی پارادایم رویکردی است که برای طراحی و پیاده سازی برنامه ها استفاده می شود. اینها 114 | رویکردها شامل مجموعه ای از قوانین و مفاهیم است که تعیین می کند برنامه ها چگونه باید باشند 115 | نوشته شده و نحوه اجرای برنامه های مختلف برنامه نویسی._ 116 | ### رایج ترین پارادایم های برنامه نویسی عبارتند از 117 | - رویه ای 118 | - شی گرا 119 | - کاربردی 120 | - مبتنی بر منطق 121 | - رویداد محور 122 | - امنیت 123 | - وب (مبتنی بر وب) 124 | 125 | _هر پارادایم برنامه نویسی مزایا و معایب خاص خود را دارد و انتخاب یک 126 | پارادایم متناسب با نیازهای پروژه شما می تواند به بهبود کیفیت برنامه و کاهش آن کمک کند 127 | هزینه های توسعه._ 128 | 129 |
130 | 131 | ## 💠 داستان پایتون (تاریخچه) 132 | > پایتون یک زبان برنامه نویسی سطح بالا، تفسیر شده و همه منظوره است 133 | طراحی شده توسط Guido van Rossum در سال 1989. 134 | در ابتدا، Guido یکی از توسعه دهندگانی بود که یک بازی در عملیات Amoeba نوشت 135 | سیستم با استفاده از زبان C او بنا به دلایلی ایده ایجاد الف را مطرح کرد 136 | زبان برنامه نویسی سطح بالا که برای برنامه نویسی بهتر از C بود. بعد از تلاش 137 | چندین نام مختلف برای این زبان، در نهایت نام پایتون انتخاب شد. 138 | اولین نسخه از این زبان در سال 1990 منتشر شد و به طور مداوم به روز می شد. در سال 1994، 139 | نسخه دوم این زبان منتشر شد و توانست رویاهای گیدو را محقق کند 140 | در مورد طراحی یک زبان سطح بالا و شی گرا. 141 | در سال 2000 نسخه 3 زبان پایتون با پیشرفت های زیادی منتشر شد 142 | به طور قابل توجهی جنبه شی گرا پایتون را بهبود بخشید. در سال 2008، نسخه 3.0 از 143 | زبان پایتون با بهبودهای ایمنی و عملکرد بسیاری معرفی شد. 144 | از آن زمان، پایتون به یکی از پرکاربردترین زبان های برنامه نویسی در جهان تبدیل شده است 145 | جهان، و بسیاری از شرکت ها و توسعه دهندگان از آن استفاده می کنند. پایتون آسان و قدرتمند است 146 | زبانی که امکانات زیادی را برای توسعه دهندگان فراهم می کند و در حال حاضر به عنوان یکی از آنها شناخته می شود 147 | برترین زبان های برنامه نویسی دنیا 148 | 149 |
150 | 151 | ## 💠 کاربردهای پایتون: 152 | - فریمورک های توسعه وب مانند جنگو، فلسک 153 | 154 | - توسعه برنامه های دسکتاپ و ابزارهای مدیریت کنترل نسخه مانند 155 | به عنوان Git 156 | - توسعه بازی های کامپیوتری و ساخت بازی های ویدئویی با پایتون 157 | - توسعه اپلیکیشن های موبایل 158 | - تجزیه و تحلیل عکس و فیلم و پردازش سیگنال 159 | - توسعه برنامه های هوش مصنوعی مانند ربات های چت، توصیه کننده 160 | سیستم ها، سیستم های مبتنی بر پردازش گفتار و متن 161 | - بازاریابی دیجیتال و بهبود سئو 162 | - امنیت سایبری و تست نفوذ 163 | - محاسبات علمی، محاسبات عددی و حل معادلات 164 | - توسعه برنامه های کاربردی اینترنت اشیا (اینترنت اشیا) 165 | - توسعه و ساخت انواع سیستم های نظارتی و سازماندهی 166 | شبکه ها و خدمات 167 | 168 |
169 | 170 | ## 💠 الگوریتم چیست؟ 171 | یک الگوریتم دنباله ای از مراحل کاملاً تعریف شده است که یک کار خاص را انجام می دهد یا a را حل می کند 172 | مشکل خاص به عبارت دیگر، مجموعه ای از قوانین یا دستورالعمل هایی است که یک کامپیوتر 173 | برنامه برای حل یک مشکل دنبال می شود. الگوریتم ها در برنامه نویسی برای خودکارسازی استفاده می شوند 174 | پردازش می کند، تصمیم می گیرد و کارآمدترین روش های مدیریت داده ها را تعیین می کند. 175 | یک مثال ساده از یک الگوریتم، دستور پخت کیک است. دستور غذا لیست همه 176 | مواد لازم را مشخص می کند و مراحلی را که باید به ترتیبی خاص برای ایجاد آن برداشته شود، مشخص می کند 177 | محصول نهایی. به طور مشابه، در برنامه نویسی، یک الگوریتم مجموعه ای از مراحل را تعریف می کند که نیاز دارند 178 | برای دستیابی به نتیجه دلخواه به ترتیب خاصی اجرا شود. 179 | 180 |
181 | 182 | ## 💠 فلوچارت چیست؟ 183 | فلوچارت یک نمایش گرافیکی از یک فرآیند یا الگوریتم است. از نمادها و 184 | نمودارهایی برای تجسم مراحل یک فرآیند و ترتیبی که در آن رخ می دهند. 185 | فلوچارت ها معمولا در برنامه نویسی کامپیوتری، فرآیندهای تجاری، 186 | مهندسی و زمینه های دیگر برای شناسایی، تجزیه و تحلیل و بهبود فرآیندها. 187 | در یک فلوچارت، هر مرحله از فرآیند با یک جعبه یا شکل هندسی دیگر نشان داده می شود. 188 | و جریان فرآیند با فلش های متصل کننده جعبه ها نشان داده می شود. جعبه ها ممکن است 189 | حاوی دستورالعمل‌ها، محاسبات یا تصمیم‌های خاصی است و فلش‌ها نشان‌دهنده آن هستند 190 | ترتیب اجرای آنها 191 | فلوچارت ها به ساده سازی فرآیندهای پیچیده کمک می کنند و درک آنها را آسان تر می کنند. آنها 192 | به افراد اجازه می دهد تا مشکلات و تنگناهای بالقوه را در یک فرآیند شناسایی کرده و توسعه دهند 193 | راه حل های کارآمدتر یا موثرتر همچنین می توان از آنها برای برقراری ارتباط فرآیندها استفاده کرد 194 | دیگران و مستندسازی فرآیندها برای اهداف مرجع. 195 | 196 |
197 | 198 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 199 | 200 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io) 201 | -------------------------------------------------------------------------------- /English language/Chapter One/README.md: -------------------------------------------------------------------------------- 1 | # **_💢 introduction to getting started 💢_** 2 | > In this section, we are going to discuss the topics that you need to understand before starting programming so that you don't run into problems in the future. 3 | 4 | ## 🔹The topics we discuss in this chapter: 5 | 6 | - [What is programming?](#-what-is-programming) 7 | - [High, low and intermediate programming language](#-high-low-and-intermediate-programming-language) 8 | - [General purpose and special purpose languages](#-general-purpose-and-special-purpose-languages) 9 | - [Interpreted and compiler languages](#-interpreted-and-compiler-languages) 10 | - [Static, dynamic, strong and weak typing languages](#-static-dynamic-strong-and-weak-typing-languages-) 11 | - [Programming paradigms](#-programming-paradigms-) 12 | - [The story of Python (History)](#-the-story-of-python-history) 13 | - [Applications of Python](#-applications-of-python-) 14 | - [What is the algorithm?](#-what-is-the-algorithm) 15 | - [What is a flowchart?](#-what-is-a-flowchart) 16 | 17 |
18 | 19 | ## 🔰 What is programming? 20 | > Programming is the process of writing code (text) to build software, programs, websites 21 | and mobile applications. In general, programmers use a programming language to create 22 | instructions for the computer to create a program (talk to the computer). These 23 | instructions may include mathematical calculations, data processing, file management, 24 | networking, and many other operations 25 | 26 |
27 | 28 | ## 💠 High, low and intermediate programming language 29 | - High, low and intermediate programming language : 30 | These languages are designed to develop programs of varying complexity and are easy for 31 | programmers to understand and write. High-level languages are commonly used to 32 | develop web applications, desktop software, and computer games. For example: Java, 33 | Python, C#, JavaScript and PHP. 34 | 35 | - Low-level programming language: 36 | These languages are designed for more precise control and more productivity in computer 37 | systems. Low-level languages are directly compatible with computer hardware and 38 | architecture, and examples include machine languages and related languages such as 39 | assembly language. 40 | - Low-level programming language: 41 | These languages are placed between high-level and low-level languages and are usually 42 | used to translate code written in a high-level language into machine code. As an example, 43 | we can mention languages like C and C++, which are used in some cases to develop 44 | software with great complexity. 45 | 46 |
47 | 48 | ## 💠 General purpose and special purpose languages 49 | _Computer languages can be divided into two categories: general-purpose and special purpose (or specialized):_ 50 | 51 | - Multipurpose languages or General Purpose Language : 52 | These languages are used to solve many problems and are used to program different types of programs, including applications, system, web, etc. In other words, general languages have the ability to solve various problems and they can be used for various applications. Some examples of 53 | common languages include Java, Python, C++, and C#. 54 | But they are not great in all areas and maybe they are great in only one area 55 | 56 | 57 | - Special Purpose Language: 58 | These languages are designed to solve specific and more limited problems and are mostly used in fields such as cognitive science, image 59 | processing, software engineering, website design, natural language processing, etc. In 60 | other words, specific languages are chosen for these applications because of their 61 | greater adjustability and more precise definition for specific problems. Some examples of 62 | specific languages include MATLAB, R, SQL, HTML, and CSS. 63 | These languages can only be used in their specialized field 64 | 65 | _In short, general languages are used to solve a wider variety of problems, while specialized 66 | languages are designed to solve more specific and limited problems._ 67 | 68 |
69 | 70 | ## 💠 Interpreted and compiler languages 71 | _Programming languages are divided into two general categories: "compiler" and "interpreted languages"._ 72 | 73 | - Compiled languages, through a computer program called a compiler, convert the source 74 | code written in the programming language into executable code. When the compiler 75 | converts the source code into executable code, it fully interprets all the components of 76 | the programming language and looks for the instructions in the source code. Languages 77 | such as C, C++, Fortran, and Pascal are examples of translated languages. 78 | 79 | 80 | - Interpreted languages execute the source code interpretatively (ie line by line) instead of 81 | converting it completely into executable code. In interpreted languages, a program is read 82 | line by line and each line is examined and executed immediately. Languages such as 83 | Python, Ruby, and JavaScript are examples of interpreted languages. 84 | 85 |
86 | 87 | ## 💠 Static, dynamic, strong and weak typing languages : 88 | _Programming languages are divided into four categories in terms of typing:_ 89 | 90 | - Static typing type: 91 | In this type of programming language, the type of the variables is specified at compile 92 | time and the compiler checks before executing the code that any data type used 93 | corresponds to the type defined. 94 | The main advantage of using this type of programming language is increasing reliability for 95 | large and complex programs. 96 | Example: Java, C++, C# 97 | 98 | 99 | - Dynamic Typing: 100 | This type of writing, values and types of variables are checked at runtime instead of 101 | compilation. However, this type of programming language is very widespread in small and 102 | simple applications and is very widely used in programming languages such as Python. 103 | Example: Python, Ruby, JavaScript 104 | 105 | - Strong Typing: 106 | In this type of programming language, we do not have any restrictions on accepting 107 | restrictions, changing the type of a variable is possible only when it is logically managed 108 | and usually requires that the variable be changed, but in other cases it is completely 109 | avoided. 110 | Example: Java, C++, C# 111 | 112 | - Weak Typing: 113 | This type of writing is similar to the type of dynamic writing, with the difference that here 114 | the data type conversion is done with easy access and without checking the rules. After 115 | validating the data type, its type is automatically determined according to the type of operation. 116 | Example: PHP, Perl, JavaScript. 117 | 118 |
119 | 120 | ## 💠 Programming paradigms : 121 | _Paradigm programming is an approach used to design and implement programs. These 122 | approaches include a set of rules and concepts that determine how programs should be 123 | written and how different programming practices should be implemented._ 124 | ### The most common programming paradigms include 125 | - Procedural 126 | - Object-oriented 127 | - functional 128 | - Logic-based 129 | - event-driven 130 | - Security 131 | - Web (Web-based) 132 | 133 | _Each programming paradigm has its own advantages and disadvantages, and choosing a 134 | paradigm that suits your project needs can help improve program quality and reduce 135 | development costs._ 136 | 137 |
138 | 139 | ## 💠 The story of Python (History) 140 | > Python is a high-level, interpreted, general-purpose programming language that was 141 | designed by Guido van Rossum in 1989. 142 | Initially, Guido was one of the developers who wrote a game in the Amoeba operating 143 | system using the C language. For some reasons, he came up with the idea of creating a 144 | high-level programming language that was better than C for programming. After trying 145 | several different names for this language, the name Python was finally chosen. 146 | The first version of this language was released in 1990 and was constantly updated. In 1994, 147 | the second version of this language was released and was able to realize Guido's dreams 148 | about designing a high-level and object-oriented language. 149 | In 2000, version 3 of the Python language was released with many improvements that 150 | significantly improved the object-oriented aspect of Python. In 2008, version 3.0 of the 151 | Python language was introduced with many safety and performance improvements. 152 | Since then, Python has become one of the most widely used programming languages in the 153 | world, and many companies and developers use it. Python is an easy and powerful 154 | language that provides many features for developers and is currently recognized as one of 155 | the top programming languages in the world. 156 | 157 |
158 | 159 | ## 💠 Applications of Python : 160 | - Web development and web development frameworks such as Django, Flask and 161 | Pyramid 162 | - Development of desktop applications and version control management tools such 163 | as Git 164 | - Developing computer games and making video games with Python 165 | - Development of mobile applications 166 | - Photo and video analysis and signal processing 167 | - Development of artificial intelligence programs such as chat bots, recommender 168 | systems, systems based on speech and text processing 169 | - Digital marketing and SEO improvement 170 | - Cyber security and penetration testing 171 | - Scientific computing, numerical calculations and solving equations 172 | - Development of IoT applications (Internet of Things) 173 | - Development and construction of various monitoring systems and organization of 174 | networks and services. 175 | 176 |
177 | 178 | ## 💠 What is the algorithm? 179 | 180 | An algorithm is a sequence of well-defined steps that perform a specific task or solve a 181 | particular problem. In other words, it is a set of rules or instructions that a computer 182 | program follows to solve a problem. Algorithms are used in programming to automate 183 | processes, make decisions, and determine the most efficient ways of handling data. 184 | A simple example of an algorithm is a recipe for baking a cake. The recipe lists all the 185 | necessary ingredients and defines the steps to be taken in a specific order to create the 186 | finished product. Similarly, in programming, an algorithm defines a set of steps that need 187 | to be executed in a specific order to achieve the desired outcome. 188 | 189 |
190 | 191 | ## 💠 What is a flowchart? 192 | A flowchart is a graphical representation of a process or algorithm. It uses symbols and 193 | diagrams to visualize the steps of a process, and the sequence in which they occur. 194 | Flowcharts are commonly used in computer programming, business processes, 195 | engineering, and other fields to identify, analyze, and improve processes. 196 | In a flowchart, each step in the process is represented by a box or other geometric shape, 197 | and the flow of the process is indicated by arrows connecting the boxes. The boxes may 198 | contain specific instructions, calculations, or decisions, and the arrows represent the 199 | order in which they are performed. 200 | Flowcharts help to simplify complex processes and make them easier to understand. They 201 | allow people to identify potential problems and bottlenecks in a process, and to develop 202 | more efficient or effective solutions. They can also be used to communicate processes to 203 | others and to document processes for reference purposes. 204 | 205 |
206 | 207 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 208 | [graycubeteam.github.io](graycubeteam.github.io) 209 | **license by gray cube team** 210 | 211 | -------------------------------------------------------------------------------- /Persian language/Chapter Three/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹موضوعاتی که در این فصل بحث می کنیم: 2 | 3 | - [مفهوم متغیر](#مفهوم-متغیر) 4 | 5 | - [نحوه تعریف متغیر در پایتون](#نحوه-تعریف-متغیر-در-پایتون) 6 | - [قوانین برای متغیرهای پایتون](#%EF%B8%8F-قوانین-برای-متغیرهای-پایتون) 7 | 8 | - [انواع داده ها در پایتون](#-انواع-داده-پایتون) 9 | 10 | - (ا[string](#-رشته-ها-در-پایتون), [integers](#-اعداد-در-پایتون), [bool](#-بولین), [float](#-اعداد-در-پایتون)) 11 | - مجموعه داده ها ([List](#-لیست-ها), [Tuple](#-تاپل), [Dictionaries](#-دیکشنری-ها), [set](#-مجموعه)) 12 | 13 | - [تبدیل انواع داده ها به یک دیگر](#تبدیل-انواع-داده-ها-به-یکدیگر) 14 | 15 |
16 | 17 | ## 💎مفهوم متغیر 18 | > در پایتون، متغیر نامی است که به یک مقدار اشاره دارد. برای ذخیره و دستکاری داده ها استفاده می شود. هنگامی که متغیری را در پایتون ایجاد می کنید، باید نامی برای آن انتخاب کنید، به آن مقدار اختصاص دهید و نوع داده آن را اعلام کنید (اگرچه در بیشتر موارد، پایتون به طور خودکار نوع داده را بر اساس مقدار اختصاص داده شده تشخیص می دهد). 19 | 20 | **⭕️ مانند ظرفی است که در آن چیزی می ریزیم و بعد از آن استفاده می کنیم** 21 | 22 |
23 | 24 | # 25 | 26 | ### 🔻نحوه تعریف متغیر در پایتون🔻 27 | برای تعریف متغیر در پایتون ابتدا نام متغیر را مشخص می کنیم و سپس با استفاده از علامت مساوی (=) مقدار مورد نظر را به متغیر اختصاص می دهیم. مثلا: 28 | 29 | ```python: 30 | name = "John" 31 | age = 30 32 | height = 1.75 33 | ``` 34 | 35 | # 36 |
37 | 38 | ### ♨️ قوانین برای متغیرهای پایتون: 39 | - نام متغیر باید با یک حرف یا کاراکتر زیرخط شروع شود 40 | - نام متغیر نمی تواند با عدد شروع شود 41 | - نام متغیر فقط می تواند شامل کاراکترهای عددی و زیرخط باشد (A-z، 0-9 و _ ) 42 | - نام متغیرها به حروف بزرگ و کوچک حساس هستند (سن، سن و AGE سه متغیر متفاوت هستند) 43 | - نام متغیر نمی تواند هیچ یک از کلمات کلیدی پایتون باشد. 44 | 45 | مثلا: 46 | ```python: 47 | myvar = "John" 48 | my_var = "John" 49 | _my_var = "John" 50 | myVar = "John" 51 | MYVAR = "John" 52 | myvar2 = "John" 53 | ``` 54 | نام متغیرهای غیرقانونی: 55 | ```python: 56 | 2myvar = "John" 57 | my-var = "John" 58 | my var = "John" 59 | ``` 60 | # 61 | ### 💢 متغیرهای پایتون - چندین مقدار اختصاص دهید 62 | #### 🔹متغیرهای چندگانه 63 | پایتون به شما این امکان را می دهد که در یک خط به چندین متغیر مقادیر اختصاص دهید: 64 | ```python: 65 | x, y, z = "Orange", "Banana", "Cherry" 66 | print(x) 67 | print(y) 68 | print(z) 69 | ``` 70 | #### 🔹یک مقدار به چند متغیر 71 | و می توانید یک مقدار را به چندین متغیر در یک خط اختصاص دهید: 72 | ```python: 73 | x = y = z = "Orange" 74 | print(x) 75 | print(y) 76 | print(z) 77 | ``` 78 | ### 💢خروجی متغییر 79 | #### 🔹خروجی متغییر ها 80 | تابع print() Python اغلب برای خروجی متغیرها استفاده می شود. 81 | ```python: 82 | x = "Python is awesome" 83 | print(x) 84 | ``` 85 | خروجی : 86 | ```python: 87 | Python is awesome 88 | ``` 89 | در تابع print() شما چندین متغیر را که با کاما از هم جدا شده اند، خروجی می دهید: 90 | ```python: 91 | x = "Python" 92 | y = "is" 93 | z = "awesome" 94 | print(x, y, z) 95 | ``` 96 | خروجی : 97 | ```python: 98 | Python is awesome 99 | ``` 100 | همچنین می توانید از عملگر + برای خروجی چندین متغیر استفاده کنید: 101 | ```python: 102 | x = "Python" 103 | y = "is" 104 | z = "awesome" 105 | print(x + y + z) 106 | ``` 107 | خروجی : 108 | ```python: 109 | Python is awesome 110 | ``` 111 | **🛑 به کاراکتر Space بعد از "Python" و "is" توجه کنید، بدون آنها نتیجه "Pythonisawesome" خواهد بود.** 112 | 113 | برای اعداد، کاراکتر + به عنوان یک عملگر ریاضی عمل می کند: 114 | ```python: 115 | x = 5 116 | y = 10 117 | print(x + y) 118 | ``` 119 | خروجی : 120 | ```python: 121 | 15 122 | ``` 123 | مثال : 124 | ```python 125 | name = "John" 126 | message = "Hello, " + name + "!" 127 | print(message) # Output: Hello, John! 128 | ``` 129 |
130 | 131 | *** 132 | 133 |
134 | 135 | ## 💎 انواع داده پایتون 136 | > در پایتون، یک نوع داده به نوع مقداری که یک متغیر در خود نگه می دارد اشاره دارد. پایتون چندین نوع داده داخلی دارد از جمله: 137 | 138 | - Integers (int): اعداد کامل بدون اعشار 139 | - Floating-point numbers (float): اعداد با اعشار 140 | - Strings (str): دنباله ترتیب کاراکترهای محصور شده در نقل قول (تک یا دوتایی) 141 | - Booleans (bool): مقادیر درست یا غلط برای عملیات منطقی 142 | - Lists (list): مجموعه مرتب شده و قابل تغییر ا مقادیر 143 | - Tuples (tuple): مجموعه‌ای مرتب و تغییرناپذیر از مقادیر 144 | - Sets (set): مجموعه نامرتب و قابل تغییر از مقادیر منحصر به فرد محصور 145 | - Dictionaries (dict): مجموعه‌ای از جفت‌های کلید-مقدار. 146 | 147 | **انواع داده ها مهم هستند زیرا نوع عملیاتی را که می توانیم روی یک متغیر انجام دهیم، نحوه رفتار آن در موقعیت های خاص و نحوه ذخیره آن در حافظه را تعیین می کنند.** 148 |
149 | 150 | # 151 | 152 |
153 | 154 | ### 📌 رشته ها در پایتون 155 | > رشته‌ها در پایتون توسط یک علامت نقل قول یا دو علامت نقل قول احاطه شده‌اند. 156 | **'hello' مثل این هست "hello".** 157 | مثال: 158 | ```python 159 | print("Hello") 160 | print('Hello') 161 | ``` 162 | خروجی : 163 | ```python: 164 | Hello 165 | Hello 166 | ``` 167 | #### 🔹رشته را به یک متغیر اختصاص دهید 168 | تخصیص یک رشته به یک متغیر با نام متغیر و به دنبال آن علامت مساوی و رشته انجام می شود: 169 | مثال: 170 | ```python: 171 | a = "Hello" 172 | print(a) 173 | ``` 174 | خروجی : 175 | ```python: 176 | Hello 177 | ``` 178 | #### 🔹رشته های چند خطی 179 | با استفاده از سه نقل قول می توانید یک رشته چند خطی را به یک متغیر اختصاص دهید: 180 | مثال: 181 | ```python: 182 | a = """Lorem ipsum dolor sit amet, 183 | consectetur adipiscing elit, 184 | sed do eiusmod tempor incididunt 185 | ut labore et dolore magna aliqua.""" 186 | print(a) 187 | 188 | #or 189 | 190 | a = """Lorem ipsum dolor sit amet, 191 | consectetur adipiscing elit, 192 | sed do eiusmod tempor incididunt 193 | ut labore et dolore magna aliqua.""" 194 | print(a) 195 | ``` 196 | خروجی : 197 | ```python: 198 | Lorem ipsum dolor sit amet, 199 | consectetur adipiscing elit, 200 | sed do eiusmod tempor incididunt 201 | ut labore et dolore magna aliqua. 202 | ``` 203 | 204 | #### 💢 برش رشته ها 205 | با استفاده از نحو slice می توانید طیف وسیعی از کاراکترها را برگردانید. 206 | برای برگرداندن بخشی از رشته، شاخص شروع و اندیس پایان را که با یک دو نقطه از هم جدا شده اند، مشخص کنید. 207 | مثال: 208 | ```python: 209 | b = "Hello, World!" 210 | print(b[2:5]) 211 | ``` 212 | خروجی : 213 | ```python: 214 | llo 215 | ``` 216 | **⭕️نکته: کاراکتر اول دارای شاخص 0 است.** 217 | 218 | #### 💢 رشته ها را اصلاح کنید 219 | پایتون مجموعه ای از متدهای داخلی دارد که می توانید روی رشته ها استفاده کنید. 220 | Example: 221 | ```python: 222 | string = "python is amazing" 223 | print(string.capitalize()) #capitalize(): 224 | # Output: "Python is amazing" 225 | 226 | string = "python is amazing" 227 | print(string.upper()) 228 | # Output: "PYTHON IS AMAZING" 229 | 230 | string = "PYTHON IS AMAZING" 231 | print(string.lower()) 232 | # Output: "python is amazing" 233 | 234 | string = "Python, is, amazing" 235 | lst = string.split(",") 236 | print(lst) 237 | # Output: ['Python', ' is', ' amazing'] 238 | 239 | string = "Python is amazing" 240 | new_string = string.replace("Python", "Java") 241 | print(new_string) 242 | # Output: "Java is amazing" 243 | 244 | string = "PYTHON IS AMAZING" 245 | print(len(string)) 246 | # Output: 17 247 | ``` 248 | **⭕️[String Methods](https://www.w3schools.com/python/python_strings_methods.asp)⭕️** 249 | 250 | Example : 251 | ```python: 252 | a = "Alireza " 253 | b = "Allahyarian" 254 | print(a+b) 255 | ``` 256 | 257 | Output : 258 | ```python: 259 | Alireza Allahyarian 260 | ``` 261 | 262 | # 263 | 264 | ### 📌 اعداد در پایتون 265 | سه نوع عددی در پایتون وجود دارد: 266 | 267 | - int 268 | - float 269 | - complex 270 | 271 | مثال : 272 | ```python: 273 | x = 1 # int 274 | y = 2.8 # float 275 | z = 1j # complex 276 | ``` 277 | #### 💢 اعداد صحیح 278 | عدد صحیح، یک عدد کامل، مثبت یا منفی، بدون اعشار، با طول نامحدود است. 279 | 280 | مثال : 281 | ```python: 282 | x = 1 283 | y = 35656222554887711 284 | z = -3255522 285 | 286 | print(type(x)) 287 | print(type(y)) 288 | print(type(z)) 289 | ``` 290 | 291 | خروجی : 292 | ```python: 293 | 294 | 295 | 296 | ``` 297 | 298 | ▫️ یک مثال کمی کاربردی تر: 299 | ```python: 300 | # Define a value of type int and assign a value to it 301 | age = 30 302 | print(age) 303 | 304 | # Perform arithmetic operations using int changes 305 | year_born = 2023 - age 306 | print("you in the year", year_born, "you are born") 307 | ``` 308 | خروجی : 309 | ```python: 310 | you in the year 1,993 you are born 311 | ``` 312 | 313 | #### 💢 اعداد اعشاری 314 | اعداداعشاری یک عدد مثبت یا منفی است که شامل یک یا چند اعشار است. 315 | 316 | مثال : 317 | ```python: 318 | x = 1.10 319 | y = 1.0 320 | z = -35.59 321 | 322 | print(type(x)) 323 | print(type(y)) 324 | print(type(z)) 325 | ``` 326 | 327 | خروجی : 328 | ```python: 329 | 330 | 331 | 332 | ``` 333 | 334 | #### 💢 اعداد مختلط 335 | اعداد مختلط با یک "j" به عنوان قسمت خیالی نوشته می شوند: 336 | 337 | مثال : 338 | ```python: 339 | x = 3+5j 340 | y = 5j 341 | z = -5j 342 | 343 | print(type(x)) 344 | print(type(y)) 345 | print(type(z)) 346 | ``` 347 | 348 | خروجی : 349 | ```python: 350 | 351 | 352 | 353 | ``` 354 | 355 | # 356 | 357 | ### 📌 بولین 358 | اBoolean یکی از دو مقدار True یا False را نشان می دهد. 359 | 360 | ##### 🔹مقادیر بولی 361 | در برنامه نویسی اغلب باید بدانید که آیا یک عبارت True یا False است. 362 | 363 | شما می توانید هر عبارتی را در پایتون ارزیابی کنید و یکی از دو پاسخ درست یا غلط را دریافت کنید. 364 | 365 | وقتی دو مقدار را با هم مقایسه می کنید، عبارت مورد ارزیابی قرار می گیرد و پایتون پاسخ بولی را برمی گرداند: 366 | 367 | مثال : 368 | ```python: 369 | print(10 > 9) 370 | print(10 == 9) 371 | print(10 < 9) 372 | ``` 373 | 374 | مثال : 375 | ```python: 376 | True 377 | False 378 | False 379 | ``` 380 | 381 | # 382 | 383 | ### 📌 ساختارهای داده (فهرست، تاپل، دیکشنری، مجموعه) 384 | 385 | #### 💢 لیست ها 386 | لیست ها برای ذخیره چندین مورد در یک متغیر استفاده می شوند. 387 | 388 | لیست ها یکی از 4 نوع داده داخلی در پایتون هستند که برای ذخیره مجموعه داده ها استفاده می شوند، 3 نوع دیگر Tuple، Set و Dictionary هستند که همه با کیفیت ها و کاربردهای متفاوتی هستند. 389 | 390 | لیست ها با استفاده از براکت ایجاد می شوند: 391 | 392 | مثال : 393 | ```python: 394 | thislist = ["apple", "banana", "cherry"] 395 | print(thislist) 396 | ``` 397 | 398 | مثال : 399 | ```python: 400 | ['apple', 'banana', 'cherry'] 401 | ``` 402 | 403 | دسترسی به آیتم یک لیست: 404 | مثال : 405 | ```python: 406 | thislist = ["apple", "banana", "cherry"] 407 | print(thislist[1])) 408 | ``` 409 | خروجی : 410 | ```python: 411 | banana 412 | ``` 413 | **⭕️ اولین مورد دارای شاخص 0 است.** 414 | 415 | **⭕️ نمایه سازی منفی یعنی شروع از انتها -1 به آخرین مورد، -2 به دومین مورد آخر و غیره اشاره دارد.** 416 | 417 | محدوده شاخص ها: 418 | > می‌توانید با تعیین مکان شروع و پایان محدوده، محدوده‌ای از شاخص‌ها را مشخص کنید. 419 | 420 | 421 | مثال : 422 | ```python: 423 | thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] 424 | print(thislist[2:5]) 425 | ``` 426 | خروجی : 427 | ```python: 428 | ['cherry', 'orange', 'kiwi'] 429 | ``` 430 | 431 | 🔶 تغییر موارد لیست: 432 | > برای تغییر مقدار یک مورد خاص، به شماره فهرست مراجعه کنید 433 | 434 | مثال : 435 | ```python: 436 | thislist = ["apple", "banana", "cherry"] 437 | thislist[1] = "blackcurrant" 438 | print(thislist) 439 | ``` 440 | خروجی : 441 | ```python: 442 | ['apple', 'blackcurrant', 'cherry'] 443 | ``` 444 | 445 | 🔶 محدوده ای از مقادیر آیتم ها را تغییر دهید 446 | > برای تغییر مقدار اقلام در یک محدوده خاص، لیستی با مقادیر جدید تعریف کنید و به محدوده اعداد فهرستی که می خواهید مقادیر جدید را درج کنید مراجعه کنید. 447 | 448 | مثال : 449 | ```python: 450 | thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"] 451 | thislist[1:3] = ["blackcurrant", "watermelon"] 452 | print(thislist) 453 | ``` 454 | خروجی : 455 | ```python: 456 | ['apple', 'blackcurrant', 'watermelon', 'orange', 'kiwi', 'mango'] 457 | ``` 458 | 459 | 🔶 موارد را درج کنید 460 | > برای درج یک آیتم لیست جدید، بدون جایگزینی هیچ یک از مقادیر موجود، می توانیم از متد insert() استفاده کنیم. 461 | مثال : 462 | ```python: 463 | thislist = ["apple", "banana", "cherry"] 464 | thislist.insert(2, "watermelon") 465 | print(thislist) 466 | ``` 467 | خروجی : 468 | ```python: 469 | ['apple', 'banana', 'watermelon', 'cherry'] 470 | ``` 471 | **⭕️ در نتیجه مثال بالا، لیست اکنون شامل 4 مورد خواهد بود** 472 | 473 | 🔶 List Methods 474 | ```python: 475 | my_list = [ 1 , 2 , 3 ] #append 476 | my_list.append(4) 477 | print(my_list) # Output: [1, 2, 3, 4] 478 | 479 | my_list = [1, 2, 3] 480 | my_list.extend([4, 5]) 481 | print(my_list) # Output: [1, 2, 3, 4, 5] 482 | 483 | my_list = [1, 2, 3] 484 | my_list.insert(1, 4) 485 | print(my_list) # Output: [1, 4, 2, 3] 486 | 487 | my_list = [1, 2, 3] 488 | my_list.remove(2) 489 | print(my_list) # output: [1, 3] 490 | 491 | my_list = [1, 2, 3] 492 | popped = my_list.pop() 493 | print(popped) # Output: 3 494 | print(my_list) # output: [1, 2] 495 | 496 | my_list = [3, 1, 4, 2, 5] 497 | my_list.sort() 498 | print(my_list) # Output: [1, 2, 3, 4, 5] 499 | ``` 500 | 501 | #### 💢 دیکشنری ها 502 | دیکشنری ها برای ذخیره مقادیر داده در جفت کلید:مقدار استفاده می شوند. 503 | دیکشنری مجموعه ای است که سفارش داده شده*، قابل تغییر است و اجازه تکرار ندارد. 504 | 505 | مثال : 506 | ```python: 507 | thisdict = { 508 | "brand": "Ford", 509 | "model": "Mustang", 510 | "year": 1964 511 | } 512 | print(thisdict) 513 | ``` 514 | خروجی : 515 | ```python: 516 | {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} 517 | ``` 518 | 519 | 🔶 آیتم های دیکشنری 520 | > آیتم های دیکشنری مرتب، قابل تغییر هستند و اجازه تکرار ندارند. 521 | > آیتم های دیکشنری به صورت جفت کلید: ارزش ارائه می شوند و می توان با استفاده از نام کلید به آنها اشاره کرد. 522 | 523 | مثال : 524 | ```python: 525 | thisdict = { 526 | "brand": "Ford", 527 | "model": "Mustang", 528 | "year": 1964 529 | } 530 | print(thisdict["brand"]) 531 | ``` 532 | مثال : 533 | ```python: 534 | Ford 535 | ``` 536 | 537 | **⭕️ دیکشنری ها قابل تغییر هستند، به این معنی که بعد از ایجاد دیکشنری می توانیم موارد را تغییر دهیم، اضافه یا حذف کنیم.** 538 | 539 | تکراری مجاز نیست 540 | > دیکشنری نمی تواند دو مورد با یک کلید داشته باشد: 541 | 542 | مثال : 543 | ```python: 544 | thisdict = { 545 | "brand": "Ford", 546 | "model": "Mustang", 547 | "year": 1964, 548 | "year": 2020 549 | } 550 | print(thisdict) 551 | ``` 552 | خروجی : 553 | ```python: 554 | {'brand': 'Ford', 'model': 'Mustang', 'year': 2020} 555 | ``` 556 | 557 | 🔶 سازنده dict(). 558 | > همچنین می توان از سازنده dict() برای ساخت دیکشنری استفاده کرد. 559 | مثال : 560 | ```python: 561 | thisdict = dict(name = "John", age = 36, country = "Norway") 562 | print(thisdict) 563 | ``` 564 | خروجی : 565 | ```python: 566 | {'name': 'John', 'age': 36, 'country': 'Norway'} 567 | ``` 568 | 569 | 🔶 تغییر مقدار 570 | > می توانید مقدار یک مورد خاص را با مراجعه به نام کلید آن تغییر دهید: 571 | 572 | مثال : 573 | ```python: 574 | thisdict = { 575 | "brand": "Ford", 576 | "model": "Mustang", 577 | "year": 1964 578 | } 579 | thisdict["year"] = 2018 580 | ``` 581 | مثال : 582 | ```python: 583 | {'brand': 'Ford', 'model': 'Mustang', 'year': 2018} 584 | ``` 585 | 586 | 🔶 Dictionary Methods 587 | 588 | Example : 589 | ```python: 590 | # clear(): clear all dictionary items 591 | d = {1: 'red', 2: 'blue', 3: 'green'} 592 | d.clear() 593 | print(d) # Output: {} 594 | 595 | 596 | #copy(): Copy a dictionary 597 | d = {1: 'red', 2: 'blue', 3: 'green'} 598 | d1 = d.copy() 599 | print(d1) # Output: {1: 'red', 2: 'blue', 3: 'green'} 600 | 601 | 602 | #get(): Gets the value corresponding to a key, returning the default value if the key does not exist. 603 | d = {1: 'red', 2: 'blue', 3: 'green'} 604 | print(d.get(1)) # Output: 'red' 605 | print(d.get(4, 'No color')) # Output: 'No color' 606 | 607 | 608 | #items(): return all items of the dictionary 609 | d = {1: 'red', 2: 'blue', 3: 'green'} 610 | print(d.items()) # Output: dict_items([(1, 'red'), (2, 'blue'), (3, 'green')]) 611 | 612 | 613 | #keys(): return all keys of the dictionary 614 | d = {1: 'red', 2: 'blue', 3: 'green'} 615 | print(d.keys()) # Output: dict_keys([1, 2, 3]) 616 | 617 | 618 | #values(): return all dictionary values 619 | d = {1: 'red', 2: 'blue', 3: 'green'} 620 | print(d.values()) # Output: dict_values(['red', 'blue', 'green']) 621 | 622 | 623 | #pop(): remove an item from the dictionary using the corresponding key 624 | d = {1: 'red', 2: 'blue', 3: 'green'} 625 | d.pop(2) 626 | print(d) # Output: {1: 'red', 3: 'green'} 627 | 628 | 629 | #update(): update the dictionary by adding another dictionary 630 | d = {1: 'red', 2: 'blue', 3: 'green'} 631 | d1 = {4: 'yellow'} 632 | d.update(d1) 633 | print(d) # Output: {1: 'red', 2: 'blue', 3: 'green', 4: 'yellow'} 634 | ``` 635 | 636 | #### 💢 مجموعه 637 | مجموعه ها برای ذخیره چندین آیتم در یک متغیر استفاده می شوند. 638 | یکی از 4 نوع داده داخلی در پایتون است که برای ذخیره مجموعه داده ها استفاده می شود، 3 نوع دیگر List، Tuple و Dictionary هستند که همگی با کیفیت ها و کاربردهای متفاوتی هستند. 639 | 640 | **⭕️ موارد تنظیم شده غیر قابل تغییر هستند، اما می توانید موارد را حذف کرده و موارد جدید اضافه کنید** 641 | 642 | مثال : 643 | ```python: 644 | thisset = {"apple", "banana", "cherry"} 645 | print(thisset) 646 | ``` 647 | خروجی : 648 | ```python: 649 | {'banana', 'cherry', 'apple'} 650 | ``` 651 | 652 | - موارد مجموعه نامرتب، غیرقابل تغییر هستند و اجازه مقادیر تکراری را نمی دهند. 653 | - بدون ترتیب به این معنی است که آیتم های یک مجموعه دارای ترتیب تعریف شده ای نیستند. 654 | - آیتم های مجموعه می توانند هر بار که از آنها استفاده می کنید با ترتیب متفاوتی ظاهر شوند و نمی توان با فهرست یا کلید به آنها اشاره کرد. 655 | 656 | 🔶 به موارد مجموعه دسترسی داشته باشید 657 | > نمی توانید با مراجعه به فهرست یا کلید به موارد موجود در یک مجموعه دسترسی پیدا کنید. 658 | مثال : 659 | ```python: 660 | thisset = {"apple", "banana", "cherry"} 661 | 662 | for x in thisset: 663 | print(x) 664 | ``` 665 | خروجی : 666 | ```python: 667 | banana 668 | cherry 669 | apple 670 | ``` 671 | 672 | مثال : 673 | ```python: 674 | thisset = {"apple", "banana", "cherry"} 675 | print("banana" in thisset) 676 | ``` 677 | خروجی : 678 | ```python: 679 | True 680 | ``` 681 | 682 | 🔶 سازنده () set 683 | > همچنین می توان از سازنده set() برای ساخت مجموعه استفاده کرد. 684 | 685 | مثال : 686 | ```python: 687 | thisset = set(("apple", "banana", "cherry")) # note the double round-brackets 688 | print(thisset) 689 | ``` 690 | خروجی : 691 | ```python: 692 | {'banana', 'apple', 'cherry'} 693 | ``` 694 | 695 | 🔶 Set Methods : 696 | 697 | Example : 698 | ```python: 699 | # Union of two sets 700 | set1 = {1, 2, 3} 701 | set2 = {3, 4, 5} 702 | print(set1.union(set2)) # Output: {1, 2, 3, 4, 5} 703 | 704 | # Intersection of two sets 705 | set1 = {1, 2, 3} 706 | set2 = {3, 4, 5} 707 | print(set1.intersection(set2)) # Output: {3} 708 | 709 | # Difference of two sets 710 | set1 = {1, 2, 3} 711 | set2 = {3, 4, 5} 712 | print(set1.difference(set2)) # Output: {1, 2} 713 | ``` 714 | 715 | **⭕️[Set Methods](https://www.w3schools.com/python/python_sets_methods.asp)⭕️** 716 | 717 | 718 | #### 💢 تاپل 719 | تاپل ها برای ذخیره چندین آیتم در یک متغیر استفاده می شوند. 720 | تاپل یکی از 4 نوع داده داخلی در پایتون است که برای ذخیره مجموعه داده ها استفاده می شود، 3 نوع دیگر List، Set و Dictionary هستند که همگی با کیفیت ها و کاربردهای متفاوتی هستند. 721 | تاپل مجموعه‌ای است منظم و غیرقابل تغییر. 722 | 723 | مثال : 724 | ```python: 725 | thistuple = ("apple", "banana", "cherry") 726 | print(thistuple) 727 | ``` 728 | خروجی : 729 | ```python: 730 | ('apple', 'banana', 'cherry') 731 | ``` 732 | 733 | 🔶 سفارش داد 734 | > وقتی می گوییم تاپل ها مرتب می شوند به این معنی است که موارد دارای ترتیب مشخصی هستند و ترتیب آن تغییر نمی کند. 735 | 736 | 🔶 غیر قابل تغییر 737 | > تاپل ها غیر قابل تغییر هستند، به این معنی که پس از ایجاد تاپل نمی توانیم موارد را تغییر، اضافه یا حذف کنیم. 738 | 739 | 🔶 تکراری را مجاز کنید 740 | > از آنجایی که تاپل ها ایندکس شده اند، می توانند مواردی با همان مقدار داشته باشند: 741 | 742 | مثال : 743 | ```python: 744 | thistuple = ("apple", "banana", "cherry", "apple", "cherry") 745 | print(thistuple) 746 | ``` 747 | خروجی : 748 | ```python: 749 | ('apple', 'banana', 'cherry', 'apple', 'cherry') 750 | ``` 751 | 752 | 🔶 سازنده () tuple 753 | > همچنین می توان از سازنده ()tuple برای ساخت یک تاپل استفاده کرد. 754 | 755 | مثال : 756 | ```python: 757 | thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets 758 | print(thistuple) 759 | ``` 760 | خروجی : 761 | ```python: 762 | ('apple', 'banana', 'cherry') 763 | ``` 764 | 765 | 🔶 به موارد تاپل دسترسی پیدا کنید 766 | > در تاپل ها، دسترسی به آیتم ها دقیقاً مانند لیست ها است 767 | 768 | 🔶 تاپل ها را به روز کنید 769 | > هنگامی که یک تاپل ایجاد می شود، نمی توانید مقادیر آن را تغییر دهید. تاپل ها غیرقابل تغییر یا تغییر ناپذیر هستند که به آن نیز گفته می شود. 770 | > اما راه حلی وجود دارد. شما می توانید تاپل را به یک لیست تبدیل کنید، لیست را تغییر دهید، و لیست را دوباره به یک تاپل تبدیل کنید. 771 | 772 | مثال : 773 | ```python: 774 | x = ("apple", "banana", "cherry") 775 | y = list(x) 776 | y[1] = "kiwi" 777 | x = tuple(y) 778 | 779 | print(x) 780 | ``` 781 | خروجی : 782 | ```python: 783 | ("apple", "kiwi", "cherry") 784 | ``` 785 | 786 | **⭕️اگر می‌خواهید روی تاپل‌ها عملیات انجام دهید، می‌توانید تاپل را به لیست تبدیل کنید، لیست را تغییر دهید و لیست را دوباره به تاپل تبدیل کنید. ⭕️** 787 | 788 | 🔶 به تاپل بپیوندید 789 | > برای پیوستن به دو یا چند تاپل می توانید از عملگر + استفاده کنید: 790 | 791 | مثال : 792 | ```python: 793 | tuple1 = ("a", "b" , "c") 794 | tuple2 = (1, 2, 3) 795 | 796 | tuple3 = tuple1 + tuple2 797 | print(tuple3) 798 | ``` 799 | خروجی : 800 | ```python: 801 | ('a', 'b', 'c', 1, 2, 3) 802 | ``` 803 | 804 | 🔶 ضرب تاپل 805 | > اگر می خواهید محتوای یک تاپل را چندین بار ضرب کنید، می توانید از عملگر * استفاده کنید: 806 | 807 | مثال : 808 | ```python: 809 | fruits = ("apple", "banana", "cherry") 810 | mytuple = fruits * 2 811 | 812 | print(mytuple) 813 | ``` 814 | خروجی : 815 | ```python: 816 | ('apple', 'banana', 'cherry', 'apple', 'banana', 'cherry') 817 | ``` 818 | 819 | 🔶 Tuple Methods 820 | 821 | Example : 822 | ```python: 823 | thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) 824 | 825 | x = thistuple.count(5) 826 | 827 | print(x) #output = 2 828 | 829 | 830 | thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) 831 | 832 | x = thistuple.index(8) 833 | 834 | print(x) #output = 3 835 | ``` 836 | 837 | *** 838 | 839 | ## 💎تبدیل انواع داده ها به یکدیگر 840 | گاهی اوقات، ممکن است نیاز به انجام تبدیل بین انواع داخلی داشته باشید. برای تبدیل بین انواع، شما به سادگی از نام نوع به عنوان یک تابع استفاده می کنید. 841 | 842 | #### 🔶 عملکرد و توضیحات 843 | 844 | | Function | Description | 845 | | ----------- | ----------- | 846 | | int(x) | Converts x to an integer. base specifies the base if x is a string. | 847 | | float(x) | Converts x to a floating-point number. | 848 | | complex(x) | Creates a complex number. | 849 | | str(x) | Converts object x to a string representation. | 850 | | tuple(s) | Converts s to a tuple. | 851 | | list(s) | Converts s to a list. | 852 | | set(s) | Converts s to a set. | 853 | | dict(d) | Creates a dictionary. d must be a sequence of (key,value) tuples. | 854 | 855 | 856 | Example : 857 | ```python: 858 | # Converting a string to an integer: 859 | x = "123" 860 | y = int(x) 861 | print(y) # Output: 123 862 | 863 | # Converting a string to a float: 864 | x = "3.14" 865 | y = float(x) 866 | print(y) # Output: 3.14 867 | 868 | # Converting an integer to a string: 869 | x = 123 870 | y = str(x) 871 | print(y) # Output: "123" 872 | 873 | # Converting a float to a string: 874 | x = 3.14 875 | y = str(x) 876 | print(y) # Output: "3.14" 877 | 878 | # Converting a boolean to an integer: 879 | x = True 880 | y = int(x) 881 | print(y) # Output: 1 882 | 883 | # Converting an integer to a boolean: 884 | x = 0 885 | y = bool(x) 886 | print(y) # Output: False 887 | 888 | # Converting a string to a boolean: 889 | x = "True" 890 | y = bool(x) 891 | print(y) # Output: True 892 | 893 | # Converting a list to a tuple: 894 | x = [1, 2, 3] 895 | y = tuple(x) 896 | print(y) # Output: (1, 2, 3) 897 | 898 | # Converting a tuple to a list: 899 | x = (1, 2, 3) 900 | y = list(x) 901 | print(y) # Output: [1, 2, 3] 902 | ``` 903 | 904 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 905 | 906 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 907 | -------------------------------------------------------------------------------- /English language/Chapter Three/README.md: -------------------------------------------------------------------------------- 1 | ## 🔹The topics we discuss in this chapter: 2 | 3 | - [Concept of Variable](#concept-of-variable) 4 | 5 | - [How to define a variable in Python](#how-to-define-a-variable-in-python) 6 | - [Rules for Python variables](#%EF%B8%8F-rules-for-python-variables) 7 | 8 | - [Python Data Types](#-python-data-types) 9 | 10 | - ([string](#-python-strings), [integers](#-python-numbers), [bool](#-python-booleans), [float](#-python-numbers)) 11 | - Data Structures ([List](#-lists), [Tuple](#-tuples), [Dictionaries](#-dictionaries), [set](#-set)) 12 | 13 | - [Convert data types to each other](#convert-data-types-to-each-other) 14 | 15 |
16 | 17 | ## 💎Concept of Variable 18 | > In Python, a variable is a name that refers to a value. It is used to store and manipulate data. When you create a variable in Python, you must choose a name for it, assign it a value, and declare its data type (although in most cases, Python automatically detects the data type based on the assigned value). 19 | 20 | **⭕️ It is like a container into which we pour something and then use it** 21 | 22 |
23 | 24 | # 25 | 26 | ### 🔻How to define a variable in Python🔻 27 | To define a variable in Python, we first specify the variable name and then use the equal sign (=) to assign the desired value to the variable. For example: 28 | 29 | ```python: 30 | name = "John" 31 | age = 30 32 | height = 1.75 33 | ``` 34 | In this example, three variables named name, age, and height are defined, and they point to the values "John", 30, and 1.75, respectively. These values can be strings, integers or floats, or even other data types. 35 | # 36 |
37 | 38 | ### ♨️ Rules for Python variables: 39 | - A variable name must start with a letter or the underscore character 40 | - A variable name cannot start with a number 41 | - A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) 42 | - Variable names are case-sensitive (age, Age and AGE are three different variables) 43 | - A variable name cannot be any of the Python keywords. 44 | 45 | For example: 46 | ```python: 47 | myvar = "John" 48 | my_var = "John" 49 | _my_var = "John" 50 | myVar = "John" 51 | MYVAR = "John" 52 | myvar2 = "John" 53 | ``` 54 | Illegal variable names: 55 | ```python: 56 | 2myvar = "John" 57 | my-var = "John" 58 | my var = "John" 59 | ``` 60 | # 61 | ### 💢 Python Variables - Assign Multiple Values 62 | #### 🔹Many Values to Multiple Variables 63 | Python allows you to assign values to multiple variables in one line: 64 | ```python: 65 | x, y, z = "Orange", "Banana", "Cherry" 66 | print(x) 67 | print(y) 68 | print(z) 69 | ``` 70 | #### 🔹One Value to Multiple Variables 71 | And you can assign the same value to multiple variables in one line: 72 | ```python: 73 | x = y = z = "Orange" 74 | print(x) 75 | print(y) 76 | print(z) 77 | ``` 78 | ### 💢 Python - Output Variables 79 | #### 🔹Output Variables 80 | The Python print() function is often used to output variables. 81 | ```python: 82 | x = "Python is awesome" 83 | print(x) 84 | ``` 85 | Output : 86 | ```python: 87 | Python is awesome 88 | ``` 89 | In the print() function, you output multiple variables, separated by a comma: 90 | ```python: 91 | x = "Python" 92 | y = "is" 93 | z = "awesome" 94 | print(x, y, z) 95 | ``` 96 | Output : 97 | ```python: 98 | Python is awesome 99 | ``` 100 | You can also use the + operator to output multiple variables: 101 | ```python: 102 | x = "Python" 103 | y = "is" 104 | z = "awesome" 105 | print(x + y + z) 106 | ``` 107 | Output : 108 | ```python: 109 | Python is awesome 110 | ``` 111 | **🛑 Notice the space character after "Python " and "is ", without them the result would be "Pythonisawesome".** 112 | 113 | For numbers, the + character works as a mathematical operator: 114 | ```python: 115 | x = 5 116 | y = 10 117 | print(x + y) 118 | ``` 119 | Output : 120 | ```python: 121 | 15 122 | ``` 123 | Example : 124 | ```python 125 | name = "John" 126 | message = "Hello, " + name + "!" 127 | print(message) # Output: Hello, John! 128 | ``` 129 |
130 | 131 | *** 132 | 133 |
134 | 135 | ## 💎 Python Data Types 136 | > In Python, a data type refers to the type of value that a variable holds. Python has several built-in data types including: 137 | 138 | - Integers (int): Whole numbers without decimal points 139 | - Floating-point numbers (float): Numbers with decimal points 140 | - Strings (str): Ordered sequence of characters enclosed in quotes (single or double) 141 | - Booleans (bool): True or False values used for logical operations 142 | - Lists (list): Ordered, mutable collection of values enclosed in square brackets 143 | - Tuples (tuple): Ordered, immutable collection of values enclosed in parentheses 144 | - Sets (set): Unordered, mutable collection of unique values enclosed in curly braces 145 | - Dictionaries (dict): Collection of key-value pairs enclosed in curly braces with colons separating the keys and values. 146 | 147 | **Data types are important because they determine the type of operations we can perform on a variable, how it behaves in certain situations, and how it is stored in memory.** 148 |
149 | 150 | # 151 | 152 |
153 | 154 | ### 📌 Python Strings 155 | > Strings in python are surrounded by either single quotation marks, or double quotation marks. 156 | **'hello' is the same as "hello".** 157 | Example: 158 | ```python 159 | print("Hello") 160 | print('Hello') 161 | ``` 162 | Output : 163 | ```python: 164 | Hello 165 | Hello 166 | ``` 167 | #### 🔹Assign String to a Variable 168 | Assigning a string to a variable is done with the variable name followed by an equal sign and the string: 169 | Example: 170 | ```python: 171 | a = "Hello" 172 | print(a) 173 | ``` 174 | Output : 175 | ```python: 176 | Hello 177 | ``` 178 | #### 🔹Multiline Strings 179 | You can assign a multiline string to a variable by using three quotes: 180 | Example: 181 | ```python: 182 | a = """Lorem ipsum dolor sit amet, 183 | consectetur adipiscing elit, 184 | sed do eiusmod tempor incididunt 185 | ut labore et dolore magna aliqua.""" 186 | print(a) 187 | 188 | #or 189 | 190 | a = """Lorem ipsum dolor sit amet, 191 | consectetur adipiscing elit, 192 | sed do eiusmod tempor incididunt 193 | ut labore et dolore magna aliqua.""" 194 | print(a) 195 | ``` 196 | Output : 197 | ```python: 198 | Lorem ipsum dolor sit amet, 199 | consectetur adipiscing elit, 200 | sed do eiusmod tempor incididunt 201 | ut labore et dolore magna aliqua. 202 | ``` 203 | 204 | #### 💢 Slicing Strings 205 | You can return a range of characters by using the slice syntax. 206 | Specify the start index and the end index, separated by a colon, to return a part of the string. 207 | Example: 208 | ```python: 209 | b = "Hello, World!" 210 | print(b[2:5]) 211 | ``` 212 | Output : 213 | ```python: 214 | llo 215 | ``` 216 | **⭕️Note: The first character has index 0.** 217 | 218 | #### 💢 Modify Strings 219 | Python has a set of built-in methods that you can use on strings. 220 | Example: 221 | ```python: 222 | string = "python is amazing" 223 | print(string.capitalize()) #capitalize(): 224 | # Output: "Python is amazing" 225 | 226 | string = "python is amazing" 227 | print(string.upper()) 228 | # Output: "PYTHON IS AMAZING" 229 | 230 | string = "PYTHON IS AMAZING" 231 | print(string.lower()) 232 | # Output: "python is amazing" 233 | 234 | string = "Python, is, amazing" 235 | lst = string.split(",") 236 | print(lst) 237 | # Output: ['Python', ' is', ' amazing'] 238 | 239 | string = "Python is amazing" 240 | new_string = string.replace("Python", "Java") 241 | print(new_string) 242 | # Output: "Java is amazing" 243 | 244 | string = "PYTHON IS AMAZING" 245 | print(len(string)) 246 | # Output: 17 247 | ``` 248 | **⭕️[String Methods](https://www.w3schools.com/python/python_strings_methods.asp)⭕️** 249 | 250 | Example : 251 | ```python: 252 | a = "Alireza " 253 | b = "Allahyarian" 254 | print(a+b) 255 | ``` 256 | 257 | Output : 258 | ```python: 259 | Alireza Allahyarian 260 | ``` 261 | 262 | # 263 | 264 | ### 📌 Python Numbers 265 | There are three numeric types in Python: 266 | 267 | - int 268 | - float 269 | - complex 270 | 271 | Example : 272 | ```python: 273 | x = 1 # int 274 | y = 2.8 # float 275 | z = 1j # complex 276 | ``` 277 | #### 💢 Integer 278 | Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. 279 | 280 | Example : 281 | ```python: 282 | x = 1 283 | y = 35656222554887711 284 | z = -3255522 285 | 286 | print(type(x)) 287 | print(type(y)) 288 | print(type(z)) 289 | ``` 290 | 291 | Output : 292 | ```python: 293 | 294 | 295 | 296 | ``` 297 | 298 | ▫️ A slightly more practical example: 299 | ```python: 300 | # Define a value of type int and assign a value to it 301 | age = 30 302 | print(age) 303 | 304 | # Perform arithmetic operations using int changes 305 | year_born = 2023 - age 306 | print("you in the year", year_born, "you are born") 307 | ``` 308 | Output : 309 | ```python: 310 | you in the year 1,993 you are born 311 | ``` 312 | 313 | #### 💢 Float 314 | Float, or "floating point number" is a number, positive or negative, containing one or more decimals. 315 | 316 | Example : 317 | ```python: 318 | x = 1.10 319 | y = 1.0 320 | z = -35.59 321 | 322 | print(type(x)) 323 | print(type(y)) 324 | print(type(z)) 325 | ``` 326 | 327 | Output : 328 | ```python: 329 | 330 | 331 | 332 | ``` 333 | 334 | #### 💢 Complex 335 | Complex numbers are written with a "j" as the imaginary part: 336 | 337 | Example : 338 | ```python: 339 | x = 3+5j 340 | y = 5j 341 | z = -5j 342 | 343 | print(type(x)) 344 | print(type(y)) 345 | print(type(z)) 346 | ``` 347 | 348 | Output : 349 | ```python: 350 | 351 | 352 | 353 | ``` 354 | 355 | # 356 | 357 | ### 📌 Python Booleans 358 | Booleans represent one of two values: True or False. 359 | 360 | ##### 🔹Boolean Values 361 | In programming you often need to know if an expression is True or False. 362 | 363 | You can evaluate any expression in Python, and get one of two answers, True or False. 364 | 365 | When you compare two values, the expression is evaluated and Python returns the Boolean answer: 366 | 367 | Example : 368 | ```python: 369 | print(10 > 9) 370 | print(10 == 9) 371 | print(10 < 9) 372 | ``` 373 | 374 | Output : 375 | ```python: 376 | True 377 | False 378 | False 379 | ``` 380 | 381 | # 382 | 383 | ### 📌 Data Structures(List, Tuple, Dictionaries, set) 384 | 385 | #### 💢 Lists 386 | Lists are used to store multiple items in a single variable. 387 | 388 | Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage. 389 | 390 | Lists are created using square brackets: 391 | 392 | Example : 393 | ```python: 394 | thislist = ["apple", "banana", "cherry"] 395 | print(thislist) 396 | ``` 397 | 398 | Output : 399 | ```python: 400 | ['apple', 'banana', 'cherry'] 401 | ``` 402 | 403 | Access Items: 404 | Example : 405 | ```python: 406 | thislist = ["apple", "banana", "cherry"] 407 | print(thislist[1])) 408 | ``` 409 | Output : 410 | ```python: 411 | banana 412 | ``` 413 | **⭕️ The first item has index 0.** 414 | 415 | **⭕️ Negative indexing means start from the end -1 refers to the last item, -2 refers to the second last item etc..** 416 | 417 | Range of Indexes: 418 | > You can specify a range of indexes by specifying where to start and where to end the range. 419 | 420 | 421 | Example : 422 | ```python: 423 | thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] 424 | print(thislist[2:5]) 425 | ``` 426 | Output : 427 | ```python: 428 | ['cherry', 'orange', 'kiwi'] 429 | ``` 430 | 431 | 🔶 Change List Items: 432 | > To change the value of a specific item, refer to the index number 433 | 434 | Example : 435 | ```python: 436 | thislist = ["apple", "banana", "cherry"] 437 | thislist[1] = "blackcurrant" 438 | print(thislist) 439 | ``` 440 | Output : 441 | ```python: 442 | ['apple', 'blackcurrant', 'cherry'] 443 | ``` 444 | 445 | 🔶 Change a Range of Item Values 446 | > To change the value of items within a specific range, define a list with the new values, and refer to the range of index numbers where you want to insert the new values 447 | 448 | Example : 449 | ```python: 450 | thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"] 451 | thislist[1:3] = ["blackcurrant", "watermelon"] 452 | print(thislist) 453 | ``` 454 | Output : 455 | ```python: 456 | ['apple', 'blackcurrant', 'watermelon', 'orange', 'kiwi', 'mango'] 457 | ``` 458 | 459 | 🔶 Insert Items 460 | > To insert a new list item, without replacing any of the existing values, we can use the insert() method. 461 | 462 | Example : 463 | ```python: 464 | thislist = ["apple", "banana", "cherry"] 465 | thislist.insert(2, "watermelon") 466 | print(thislist) 467 | ``` 468 | Output : 469 | ```python: 470 | ['apple', 'banana', 'watermelon', 'cherry'] 471 | ``` 472 | **⭕️ As a result of the example above, the list will now contain 4 items** 473 | 474 | 🔶 List Methods 475 | ```python: 476 | my_list = [ 1 , 2 , 3 ] #append 477 | my_list.append(4) 478 | print(my_list) # Output: [1, 2, 3, 4] 479 | 480 | my_list = [1, 2, 3] 481 | my_list.extend([4, 5]) 482 | print(my_list) # Output: [1, 2, 3, 4, 5] 483 | 484 | my_list = [1, 2, 3] 485 | my_list.insert(1, 4) 486 | print(my_list) # Output: [1, 4, 2, 3] 487 | 488 | my_list = [1, 2, 3] 489 | my_list.remove(2) 490 | print(my_list) # output: [1, 3] 491 | 492 | my_list = [1, 2, 3] 493 | popped = my_list.pop() 494 | print(popped) # Output: 3 495 | print(my_list) # output: [1, 2] 496 | 497 | my_list = [3, 1, 4, 2, 5] 498 | my_list.sort() 499 | print(my_list) # Output: [1, 2, 3, 4, 5] 500 | ``` 501 | 502 | #### 💢 Dictionaries 503 | Dictionaries are used to store data values in key:value pairs. 504 | A dictionary is a collection which is ordered*, changeable and do not allow duplicates. 505 | 506 | Example : 507 | ```python: 508 | thisdict = { 509 | "brand": "Ford", 510 | "model": "Mustang", 511 | "year": 1964 512 | } 513 | print(thisdict) 514 | ``` 515 | Output : 516 | ```python: 517 | {'brand': 'Ford', 'model': 'Mustang', 'year': 1964} 518 | ``` 519 | 520 | 🔶 Dictionary Items 521 | > Dictionary items are ordered, changeable, and does not allow duplicates. 522 | > Dictionary items are presented in key:value pairs, and can be referred to by using the key name. 523 | 524 | Example : 525 | ```python: 526 | thisdict = { 527 | "brand": "Ford", 528 | "model": "Mustang", 529 | "year": 1964 530 | } 531 | print(thisdict["brand"]) 532 | ``` 533 | Output : 534 | ```python: 535 | Ford 536 | ``` 537 | 538 | **⭕️ Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created.** 539 | 540 | 🔶 Duplicates Not Allowed 541 | > Dictionaries cannot have two items with the same key: 542 | 543 | Example : 544 | ```python: 545 | thisdict = { 546 | "brand": "Ford", 547 | "model": "Mustang", 548 | "year": 1964, 549 | "year": 2020 550 | } 551 | print(thisdict) 552 | ``` 553 | Output : 554 | ```python: 555 | {'brand': 'Ford', 'model': 'Mustang', 'year': 2020} 556 | ``` 557 | 558 | 🔶 The dict() Constructor 559 | > It is also possible to use the dict() constructor to make a dictionary. 560 | 561 | Example : 562 | ```python: 563 | thisdict = dict(name = "John", age = 36, country = "Norway") 564 | print(thisdict) 565 | ``` 566 | Output : 567 | ```python: 568 | {'name': 'John', 'age': 36, 'country': 'Norway'} 569 | ``` 570 | 571 | 🔶 Change Values 572 | > You can change the value of a specific item by referring to its key name: 573 | 574 | Example : 575 | ```python: 576 | thisdict = { 577 | "brand": "Ford", 578 | "model": "Mustang", 579 | "year": 1964 580 | } 581 | thisdict["year"] = 2018 582 | ``` 583 | Output : 584 | ```python: 585 | {'brand': 'Ford', 'model': 'Mustang', 'year': 2018} 586 | ``` 587 | 588 | 🔶 Dictionary Methods 589 | 590 | Example : 591 | ```python: 592 | # clear(): clear all dictionary items 593 | d = {1: 'red', 2: 'blue', 3: 'green'} 594 | d.clear() 595 | print(d) # Output: {} 596 | 597 | 598 | #copy(): Copy a dictionary 599 | d = {1: 'red', 2: 'blue', 3: 'green'} 600 | d1 = d.copy() 601 | print(d1) # Output: {1: 'red', 2: 'blue', 3: 'green'} 602 | 603 | 604 | #get(): Gets the value corresponding to a key, returning the default value if the key does not exist. 605 | d = {1: 'red', 2: 'blue', 3: 'green'} 606 | print(d.get(1)) # Output: 'red' 607 | print(d.get(4, 'No color')) # Output: 'No color' 608 | 609 | 610 | #items(): return all items of the dictionary 611 | d = {1: 'red', 2: 'blue', 3: 'green'} 612 | print(d.items()) # Output: dict_items([(1, 'red'), (2, 'blue'), (3, 'green')]) 613 | 614 | 615 | #keys(): return all keys of the dictionary 616 | d = {1: 'red', 2: 'blue', 3: 'green'} 617 | print(d.keys()) # Output: dict_keys([1, 2, 3]) 618 | 619 | 620 | #values(): return all dictionary values 621 | d = {1: 'red', 2: 'blue', 3: 'green'} 622 | print(d.values()) # Output: dict_values(['red', 'blue', 'green']) 623 | 624 | 625 | #pop(): remove an item from the dictionary using the corresponding key 626 | d = {1: 'red', 2: 'blue', 3: 'green'} 627 | d.pop(2) 628 | print(d) # Output: {1: 'red', 3: 'green'} 629 | 630 | 631 | #update(): update the dictionary by adding another dictionary 632 | d = {1: 'red', 2: 'blue', 3: 'green'} 633 | d1 = {4: 'yellow'} 634 | d.update(d1) 635 | print(d) # Output: {1: 'red', 2: 'blue', 3: 'green', 4: 'yellow'} 636 | ``` 637 | 638 | #### 💢 Set 639 | Sets are used to store multiple items in a single variable. 640 | Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage. 641 | 642 | **⭕️ Set items are unchangeable, but you can remove items and add new items** 643 | 644 | Example : 645 | ```python: 646 | thisset = {"apple", "banana", "cherry"} 647 | print(thisset) 648 | ``` 649 | Output : 650 | ```python: 651 | {'banana', 'cherry', 'apple'} 652 | ``` 653 | 654 | - Set items are unordered, unchangeable, and do not allow duplicate values. 655 | - Unordered means that the items in a set do not have a defined order. 656 | - Set items can appear in a different order every time you use them, and cannot be referred to by index or key. 657 | 658 | 🔶 Access Set Items 659 | > You cannot access items in a set by referring to an index or a key. 660 | 661 | Example : 662 | ```python: 663 | thisset = {"apple", "banana", "cherry"} 664 | 665 | for x in thisset: 666 | print(x) 667 | ``` 668 | Output : 669 | ```python: 670 | banana 671 | cherry 672 | apple 673 | ``` 674 | 675 | Example : 676 | ```python: 677 | thisset = {"apple", "banana", "cherry"} 678 | print("banana" in thisset) 679 | ``` 680 | Output : 681 | ```python: 682 | True 683 | ``` 684 | 685 | 🔶 The set() Constructor 686 | > It is also possible to use the set() constructor to make a set. 687 | 688 | Example : 689 | ```python: 690 | thisset = set(("apple", "banana", "cherry")) # note the double round-brackets 691 | print(thisset) 692 | ``` 693 | Output : 694 | ```python: 695 | {'banana', 'apple', 'cherry'} 696 | ``` 697 | 698 | 🔶 Set Methods : 699 | 700 | Example : 701 | ```python: 702 | # Union of two sets 703 | set1 = {1, 2, 3} 704 | set2 = {3, 4, 5} 705 | print(set1.union(set2)) # Output: {1, 2, 3, 4, 5} 706 | 707 | # Intersection of two sets 708 | set1 = {1, 2, 3} 709 | set2 = {3, 4, 5} 710 | print(set1.intersection(set2)) # Output: {3} 711 | 712 | # Difference of two sets 713 | set1 = {1, 2, 3} 714 | set2 = {3, 4, 5} 715 | print(set1.difference(set2)) # Output: {1, 2} 716 | ``` 717 | 718 | **⭕️[Set Methods](https://www.w3schools.com/python/python_sets_methods.asp)⭕️** 719 | 720 | 721 | #### 💢 Tuples 722 | Tuples are used to store multiple items in a single variable. 723 | Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. 724 | A tuple is a collection which is ordered and unchangeable. 725 | 726 | Example : 727 | ```python: 728 | thistuple = ("apple", "banana", "cherry") 729 | print(thistuple) 730 | ``` 731 | Output : 732 | ```python: 733 | ('apple', 'banana', 'cherry') 734 | ``` 735 | 736 | 🔶 Ordered 737 | > When we say that tuples are ordered, it means that the items have a defined order, and that order will not change. 738 | 739 | 🔶 Unchangeable 740 | > Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created. 741 | 742 | 🔶 Allow Duplicates 743 | > Since tuples are indexed, they can have items with the same value: 744 | 745 | Example : 746 | ```python: 747 | thistuple = ("apple", "banana", "cherry", "apple", "cherry") 748 | print(thistuple) 749 | ``` 750 | Output : 751 | ```python: 752 | ('apple', 'banana', 'cherry', 'apple', 'cherry') 753 | ``` 754 | 755 | 🔶 The tuple() Constructor 756 | > It is also possible to use the tuple() constructor to make a tuple. 757 | 758 | Example : 759 | ```python: 760 | thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets 761 | print(thistuple) 762 | ``` 763 | Output : 764 | ```python: 765 | ('apple', 'banana', 'cherry') 766 | ``` 767 | 768 | 🔶 Access Tuple Items 769 | > In tuples, access to items is exactly like lists 770 | 771 | 🔶 Update Tuples 772 | > Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called. 773 | > But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple. 774 | 775 | Example : 776 | ```python: 777 | x = ("apple", "banana", "cherry") 778 | y = list(x) 779 | y[1] = "kiwi" 780 | x = tuple(y) 781 | 782 | print(x) 783 | ``` 784 | Output : 785 | ```python: 786 | ("apple", "kiwi", "cherry") 787 | ``` 788 | 789 | **⭕️If you want to perform operations on tuples You can convert the tuple to a list, modify the list, and convert the list back to a tuple. ⭕️** 790 | 791 | 🔶 Join Tuples 792 | > To join two or more tuples you can use the + operator: 793 | 794 | Example : 795 | ```python: 796 | tuple1 = ("a", "b" , "c") 797 | tuple2 = (1, 2, 3) 798 | 799 | tuple3 = tuple1 + tuple2 800 | print(tuple3) 801 | ``` 802 | Output : 803 | ```python: 804 | ('a', 'b', 'c', 1, 2, 3) 805 | ``` 806 | 807 | 🔶 Multiply Tuples 808 | > If you want to multiply the content of a tuple a given number of times, you can use the * operator: 809 | 810 | Example : 811 | ```python: 812 | fruits = ("apple", "banana", "cherry") 813 | mytuple = fruits * 2 814 | 815 | print(mytuple) 816 | ``` 817 | Output : 818 | ```python: 819 | ('apple', 'banana', 'cherry', 'apple', 'banana', 'cherry') 820 | ``` 821 | 822 | 🔶 Tuple Methods 823 | > Python has two built-in methods that you can use on tuples. 824 | 825 | Example : 826 | ```python: 827 | thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) 828 | 829 | x = thistuple.count(5) 830 | 831 | print(x) #output = 2 832 | 833 | 834 | thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) 835 | 836 | x = thistuple.index(8) 837 | 838 | print(x) #output = 3 839 | ``` 840 | 841 | *** 842 | 843 | ## 💎Convert data types to each other 844 | Sometimes, you may need to perform conversions between the built-in types. To convert between types, you simply use the type name as a function. 845 | 846 | #### 🔶 Function & Description 847 | 848 | | Function | Description | 849 | | ----------- | ----------- | 850 | | int(x) | Converts x to an integer. base specifies the base if x is a string. | 851 | | float(x) | Converts x to a floating-point number. | 852 | | complex(x) | Creates a complex number. | 853 | | str(x) | Converts object x to a string representation. | 854 | | tuple(s) | Converts s to a tuple. | 855 | | list(s) | Converts s to a list. | 856 | | set(s) | Converts s to a set. | 857 | | dict(d) | Creates a dictionary. d must be a sequence of (key,value) tuples. | 858 | 859 | 860 | Example : 861 | ```python: 862 | # Converting a string to an integer: 863 | x = "123" 864 | y = int(x) 865 | print(y) # Output: 123 866 | 867 | # Converting a string to a float: 868 | x = "3.14" 869 | y = float(x) 870 | print(y) # Output: 3.14 871 | 872 | # Converting an integer to a string: 873 | x = 123 874 | y = str(x) 875 | print(y) # Output: "123" 876 | 877 | # Converting a float to a string: 878 | x = 3.14 879 | y = str(x) 880 | print(y) # Output: "3.14" 881 | 882 | # Converting a boolean to an integer: 883 | x = True 884 | y = int(x) 885 | print(y) # Output: 1 886 | 887 | # Converting an integer to a boolean: 888 | x = 0 889 | y = bool(x) 890 | print(y) # Output: False 891 | 892 | # Converting a string to a boolean: 893 | x = "True" 894 | y = bool(x) 895 | print(y) # Output: True 896 | 897 | # Converting a list to a tuple: 898 | x = [1, 2, 3] 899 | y = tuple(x) 900 | print(y) # Output: (1, 2, 3) 901 | 902 | # Converting a tuple to a list: 903 | x = (1, 2, 3) 904 | y = list(x) 905 | print(y) # Output: [1, 2, 3] 906 | ``` 907 | 908 | ### 🖊 the writer : Alireza Allahyarian - [Website](http://microhex.info/) - [linkedin](https://www.linkedin.com/in/alireza-allahyarian-658658258/)- [GitHub](https://github.com/graymicro) - [Tlegeram](https://t.me/graycubeteam) 909 | 910 | #### **[♦️license by gray cube team♦️](graycubeteam.github.io)** 911 | --------------------------------------------------------------------------------