ar
Feedback
Python Codes

Python Codes

الذهاب إلى القناة على Telegram

This channel will serve you all the codes and programs which are related to Python. We post the codes from the beginner level to advanced level.

إظهار المزيد
7 090
المشتركون
لا توجد بيانات24 ساعات
لا توجد بيانات7 أيام
لا توجد بيانات30 أيام

جاري تحميل البيانات...

سحابة العلامات
لا توجد بيانات
هل تواجه مشاكل؟ يرجى تحديث الصفحة أو الاتصال بمدير الدعم الخاص بنا.
الإشارات الواردة والصادرة
---
---
---
---
---
---
جذب المشتركين
مارس '24
مارس '240
في 0 قنوات
فبراير '240
في 0 قنوات
Get PRO
يناير '24
+596
في 0 قنوات
Get PRO
ديسمبر '230
في 0 قنوات
Get PRO
نوفمبر '230
في 0 قنوات
Get PRO
أكتوبر '230
في 0 قنوات
Get PRO
سبتمبر '230
في 0 قنوات
Get PRO
أغسطس '230
في 0 قنوات
Get PRO
يوليو '230
في 0 قنوات
Get PRO
يونيو '23
+68
في 0 قنوات
Get PRO
مايو '23
+94
في 0 قنوات
Get PRO
أبريل '23
+93
في 0 قنوات
Get PRO
مارس '23
+154
في 0 قنوات
Get PRO
فبراير '23
+128
في 0 قنوات
Get PRO
يناير '23
+149
في 0 قنوات
Get PRO
ديسمبر '22
+139
في 0 قنوات
Get PRO
نوفمبر '22
+103
في 0 قنوات
Get PRO
أكتوبر '22
+124
في 0 قنوات
Get PRO
سبتمبر '22
+193
في 0 قنوات
Get PRO
أغسطس '22
+225
في 0 قنوات
Get PRO
يوليو '22
+170
في 0 قنوات
Get PRO
يونيو '22
+197
في 0 قنوات
Get PRO
مايو '22
+212
في 0 قنوات
Get PRO
أبريل '22
+229
في 0 قنوات
Get PRO
مارس '22
+480
في 0 قنوات
Get PRO
فبراير '22
+265
في 0 قنوات
Get PRO
يناير '22
+225
في 0 قنوات
Get PRO
ديسمبر '21
+331
في 0 قنوات
Get PRO
نوفمبر '21
+317
في 0 قنوات
Get PRO
أكتوبر '21
+164
في 0 قنوات
Get PRO
سبتمبر '21
+327
في 0 قنوات
Get PRO
أغسطس '21
+112
في 0 قنوات
Get PRO
يوليو '21
+81
في 0 قنوات
Get PRO
يونيو '21
+192
في 0 قنوات
Get PRO
مايو '21
+122
في 0 قنوات
Get PRO
أبريل '21
+127
في 0 قنوات
Get PRO
مارس '21
+153
في 0 قنوات
Get PRO
فبراير '21
+110
في 0 قنوات
Get PRO
يناير '21
+89
في 0 قنوات
Get PRO
ديسمبر '20
+3 488
في 0 قنوات
منشورات القناة
If you want to contact us Message to this account For Ads and Freelancing Username: @Ping_TG

2
NumPy tricks for beginners : 👉 Reshaping arrays: NumPy provides the np.reshape() function, which allows you to change the shape of an array while preserving its data. This can be useful for converting between different data formats, such as converting a one-dimensional array into a two-dimensional matrix. For example, the following code reshapes a one-dimensional array into a two-dimensional matrix with two rows and three columns: import numpy as np # Create a one-dimensional NumPy array x = np.array([1, 2, 3, 4, 5, 6]) # Reshape the array into a two-dimensional matrix with 2 rows and 3 columns x_matrix = np.reshape(x, (2, 3)) # Print the resulting matrix print(x_matrix) output: [[1 2 3] [4 5 6]] 👉Stacking arrays: NumPy provides the np.vstack() and np.hstack() functions, which allow you to stack arrays vertically or horizontally. This can be useful for combining multiple arrays into a single array, or for splitting a single array into multiple arrays. For example, the following code stacks two one-dimensional arrays vertically to create a two-dimensional matrix: import numpy as np # Create two one-dimensional NumPy arrays x = np.array([1, 2, 3]) y = np.array([4, 5, 6]) # Stack the arrays vertically to create a two-dimensional matrix z = np.vstack((x, y)) # Print the resulting matrix print(z) output: [[1 2 3] [4 5 6]] 👉Broadcasting: NumPy allows you to perform mathematical operations on arrays with different shapes, using a technique called broadcasting. This allows you to perform operations on arrays of different sizes, as long as their shapes are compatible. For example, the following code adds a scalar value to each element of a two-dimensional array: import numpy as np # Create a two-dimensional NumPy array x = np.array([[1, 2, 3], [4, 5, 6]]) # Add a scalar value to each element of the array y = x + 10 # Print the resulting array print(y) output: [[11 12 13] [14 15 16]] Share and Support @Python_Codes
1 277
3
Basic NumPy for beginners: Creating a NumPy array: To create a NumPy array from a list or tuple, you can use the np.array() function. For example, the following code creates a NumPy array from a list of numbers: import numpy as np # Create a NumPy array from a list of numbers numbers = [1, 2, 3, 4, 5] numbers_array = np.array(numbers) # Print the array print(numbers_array) output: [1 2 3 4 5] Basic mathematical operations: NumPy provides functions for performing mathematical operations on arrays, such as addition, subtraction, multiplication, and division. These operations can be performed element-wise, allowing for efficient computation on large datasets. For example, the following code adds two NumPy arrays element-wise: import numpy as np # Create two NumPy arrays x = np.array([1, 2, 3, 4, 5]) y = np.array([6, 7, 8, 9, 10]) # Add the arrays element-wise z = x + y # Print the result print(z) output: [ 7 9 11 13 15] Indexing and slicing: NumPy arrays can be indexed and sliced just like lists. This allows you to access and manipulate specific elements or subarrays within an array. For example, the following code slices a NumPy array to extract the second and third elements: import numpy as np # Create a NumPy array numbers = np.array([1, 2, 3, 4, 5]) # Slice the array to extract the second and third elements subarray = numbers[1:3] # Print the result print(subarray) output: [2 3] Share and Support @Python_Codes
1 050
4
NumPy is a library for scientific computing in Python. It provides tools for working with arrays of data, including functions for mathematical operations, linear algebra, and random number generation. 👉🏻One of the key features of NumPy is its array data structure, which is similar to a list but allows for more efficient mathematical operations on large datasets. NumPy arrays can be created from existing data, such as lists or tuples, using the np.array() function. 👉🏻Once an array has been created, it can be manipulated using various NumPy functions. For example, the np.mean() function can be used to compute the mean of an array, and the np.random.rand() function can be used to generate random numbers. 👉🏻In addition to its array data structure, NumPy also provides a wide range of mathematical functions for working with arrays, such as linear algebra operations, statistical functions, and trigonometric functions. These functions can be applied to arrays element-wise, allowing for efficient computation on large datasets. Overall, NumPy is a powerful library for working with arrays of data in Python, and is widely used in the fields of scientific computing, data science, and machine learning. Share and Support @Python_Codes
1 038
5
Commonly used Python libraries are: 👉🏻NumPy: This library is used for scientific computing and working with arrays of data. It provides functions for working with arrays of data, including mathematical operations, linear algebra, and random number generation. 👉🏻Pandas: This library is used for data manipulation and analysis. It provides tools for importing, cleaning, and transforming data, as well as tools for working with time series data and performing statistical analysis. 👉🏻Matplotlib: This library is used for data visualization. It provides functions for creating a wide range of plots, including scatter plots, line plots, bar plots, and histograms. 👉🏻Scikit-learn: This library is used for machine learning. It provides a range of algorithms for classification, regression, clustering, and dimensionality reduction, as well as tools for model evaluation and selection. 👉🏻TensorFlow: This library is used for deep learning. It provides a range of tools and libraries for building and training neural networks, including support for distributed training and hardware acceleration. Share and Support @Python_Codes
1 150
6
common techniques for using the type() function in Python: Get the type of an object: my_object = "Hello, world!" my_type = type(my_object) Check if an object is of a given type: my_object = "Hello, world!" if type(my_object) == str: print("my_object is a string.") Create a new object of a given type: my_type = int my_object = my_type("1") Use the type of an object as a dictionary key: my_object = "Hello, world!" my_type = type(my_object) my_dict = {} my_dict[my_type] = my_object Use the type of an object as a set element: my_object = "Hello, world!" my_type = type(my_object) my_set = set() my_set.add(my_type) The type() function is a built-in function in Python that is used to determine the type of an object. It is a useful tool for checking the type of an object, creating objects of a specific type, and using the type of an object as a key in a dictionary or set. Share and Support @Python_Codes
1 152
7
Common techniques for using the repr() function in Python: Get the string representation of an object: my_object = "Hello, world!" my_repr = repr(my_object) Print the string representation of an object: my_object = "Hello, world!" print(repr(my_object)) Use the string representation of an object for debugging: my_object = "Hello, world!" print(f"my_object: {repr(my_object)}") Use the string representation of an object as a dictionary key: my_object = "Hello, world!" my_repr = repr(my_object) my_dict = {} my_dict[my_repr] = my_object Use the string representation of an object as a set element: my_object = "Hello, world!" my_repr = repr(my_object) my_set = set() my_set.add(my_repr) Keep in mind that the repr() function is used to generate a string representation of an object that is meant to be readable and unambiguous. The resulting string may not be the same as the original value of the object, and it may not be suitable for use in some contexts. Share and Support @Python_Codes
0
8
Common techniques for using the hash() function in Python: Get the hash value of an object: my_object = "Hello, world!" my_hash = hash(my_object) Hash multiple objects: my_object1 = "Hello, world!" my_object2 = (1, 2, 3) my_object3 = {"key": "value"} my_hash1 = hash(my_object1) my_hash2 = hash(my_object2) my_hash3 = hash(my_object3) Use the hash value for an object as a dictionary key: my_object = "Hello, world!" my_hash = hash(my_object) my_dict = {} my_dict[my_hash] = my_object Use the hash value for an object as a set element: my_object = "Hello, world!" my_hash = hash(my_object) my_set = set() my_set.add(my_hash) Keep in mind that the hash() function is used to generate a numeric value that represents the value of an object. The value of the hash may change between different runs of a Python program, so it should not be used as a unique identifier for objects unless you are sure that the hash will not change. In addition, not all objects are hashable, so it is not possible to use the hash() function with every type of object in Python. Share and Support @Python_Codes
551
9
If you want to contact us Message to this account Username: @Ping_TG
652
10
In general, the Python standard library includes many built-in functions that are available to use in your code without needing to import any additional modules. Some common examples of built-in functions include: 👉🏻 abs() : Returns the absolute value of a number. 👉🏻 all() : Returns True if all elements of an iterable are True, and False otherwise. 👉🏻 any() : Returns True if any element of an iterable is True, and False otherwise. 👉🏻 bin() : Converts an integer to a binary string. 👉🏻 bool() : Converts a value to a Boolean. 👉🏻 chr() : Returns the string representation of a Unicode character. 👉🏻 dir() : Returns a list of attributes and methods for an object. 👉🏻enumerate(): Returns an enumerate object, which contains a sequence of tuples containing the index and value of each element of an iterable. 👉🏻 filter() : Returns an iterator for elements of an iterable for which a condition is True. 👉🏻 float() : Converts a value to a floating-point number. 👉🏻 format(): Formats a string using format specifiers. 👉🏻 hash() : Returns the hash value of an object. 👉🏻 int() : Converts a value to an integer. 👉🏻 isinstance(): Returns True if an object is an instance of a given type, and False otherwise. 👉🏻 len() : Returns the length of an object. 👉🏻 list() : Converts an iterable to a list. 👉🏻 map() : Returns an iterator that applies a function to each element of an iterable. 👉🏻 max() : Returns the maximum value of an iterable. 👉🏻 min() : Returns the minimum value of an iterable. 👉🏻 next() : Returns the next element of an iterator. 👉🏻 open() : Opens a file and returns a file object. 👉🏻 ord() : Returns the Unicode code point for a character. 👉🏻 print() : Prints a message to the standard output. 👉🏻 range() : Returns a sequence of numbers. 👉🏻 repr() : Returns a string representation of an object. 👉🏻 round() : Rounds a number to a specified number of decimal places. 👉🏻 set() : Creates a set object. 👉🏻 sorted() : Returns a sorted list from an iterable. 👉🏻 str() : Converts a value to a string. 👉🏻 sum() : Returns the sum of elements in an iterable. 👉🏻 type() : Returns the type of an object. 👉🏻 zip() : Returns an iterator that combines elements from multiple iterables. Share and Support @Python_Codes
818
11
The union of two sets can be found using the union() method. Here is an example: set1 = {1, 2, 3} set2 = {3, 4, 5} union_set = set1.union(set2) This will create a new set called union_set that contains all of the items from set1 and set2. In this case, union_set will be equal to {1, 2, 3, 4, 5}. You can also use the | operator to find the union of two sets. For example: set1 = {1, 2, 3} set2 = {3, 4, 5} union_set = set1 | set2 This will produce the same result as the union() method. Keep in mind that sets are unordered collections of unique items, so the order of the items in the union set may not be the same as the order of the items in the original sets. Share and Support @Python_Codes
1 076
12
Common techniques for using the zip() function in Python: 1. Zip two lists together: list1 = [1, 2, 3] list2 = [4, 5, 6] zipped_lists = zip(list1, list2) 2. Unzip a zipped list: zipped_lists = [(1, 4), (2, 5), (3, 6)] list1, list2 = zip(*zipped_lists) 3. Loop through a zipped list: zipped_lists = [(1, 4), (2, 5), (3, 6)] for item1, item2 in zipped_lists: print(item1, item2) 4.Convert a zipped list to a dictionary: zipped_lists = [(1, 4), (2, 5), (3, 6)] my_dict = dict(zipped_lists) 5. Zip three or more lists together: list1 = [1, 2, 3] list2 = [4, 5, 6] list3 = [7, 8, 9] zipped_lists = zip(list1, list2, list3) Share and Support @Python_Codes
1 305
13
Common techniques for using the set() function in Python: 1. Create a set from a list: my_list = [1, 2, 2, 3, 3, 3] my_set = set(my_list) 2.Add an item to a set: my_set = {1, 2, 3} my_set.add(4) 3.Remove an item from a set by its value: my_set = {1, 2, 3} my_set.remove(3) 4.Check if an item is in a set: my_set = {1, 2, 3} if 3 in my_set: print("The item is in the set.") 5.Get the length of a set: my_set = {1, 2, 3} set_length = len(my_set) 6.Loop through the items in a set: my_set = {1, 2, 3} for item in my_set: print(item) 7.Get the union of two sets: set1 = {1, 2, 3} set2 = {3, 4, 5} union_set = set1.union(set2) 8.Get the intersection of two sets: set1 = {1, 2, 3} set2 = {3, 4, 5} intersection_set = set1.intersection(set2) Share and Support @Python_Codes
1 281
14
💡🐍 Did you know? You can use slices in Python to insert elements to a list in arbitrary positions? Share and Support @Pytho
💡🐍 Did you know? You can use slices in Python to insert elements to a list in arbitrary positions? Share and Support @Python_Codes
1 265
15
What are pure functions? A pure function is a function that will return the same value given the same arguments. A function is not pure if there is something outside the function that can change its return value, given the same arguments. Share and Support @Python_Codes
1 285
16
Do you want to know the recursion limit in Python? Share and Support @Python_Codes
Do you want to know the recursion limit in Python? Share and Support @Python_Codes
1 063
17
How do you check if an array is monotonic? An array is monotonic if the elements are sorted either in descending order or asc
How do you check if an array is monotonic? An array is monotonic if the elements are sorted either in descending order or ascending order. Share and Support @Python_Codes
1 153
18
round() function the round function is used to convert the floating-point into a specified number of decimals number @Python_
round() function the round function is used to convert the floating-point into a specified number of decimals number @Python_Codes
1 310
19
any() function returns True if at least one item is True in the iterable object. @Python_Codes
any() function returns True if at least one item is True in the iterable object. @Python_Codes
1 128
20
Most of the time, we don't want to share our wifi passwords, in that case, we generate a QR and stick it on the wall. @Python
Most of the time, we don't want to share our wifi passwords, in that case, we generate a QR and stick it on the wall. @Python_Codes
1 156