From a0b417253fefa94fad6bb94b37b109d079700486 Mon Sep 17 00:00:00 2001 From: Anshusinghh Date: Tue, 14 Oct 2025 18:16:11 +0530 Subject: [PATCH 1/9] Added [Term Entry] Python keywords: await #7736 --- .../concepts/keywords/terms/await/await.md | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 content/python/concepts/keywords/terms/await/await.md diff --git a/content/python/concepts/keywords/terms/await/await.md b/content/python/concepts/keywords/terms/await/await.md new file mode 100644 index 00000000000..6918b89b01a --- /dev/null +++ b/content/python/concepts/keywords/terms/await/await.md @@ -0,0 +1,74 @@ +--- +Title: 'await' +Description: 'Pauses the execution of an async function until the awaited coroutine completes.' +Subjects: + - 'Computer Science' + - 'Web Development' +Tags: + - 'Async' + - 'Await' + - 'Python' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +The **`await`** keyword pauses the execution of an asynchronous function until the awaited [coroutine](https://docs.python.org/3/library/asyncio-task.html#id2), task, or awaitable object is completed. It allows asynchronous code to be written in a way that resembles synchronous code. + +## Syntax + +```pseudo +await expression +``` + +The `await` keyword can only be used inside an `async` function. Using it outside an async function will raise a `SyntaxError`. + +## Example + +The await keyword can be used to wait for an asynchronous task before continuing: + +```py +import asyncio + +async def fetch_data(): + print("Fetching data...") + await asyncio.sleep(1) + print("Data received!") + return {"data": 42} + +async def main(): + result = await fetch_data() + print("Result:", result) + +asyncio.run(main()) +``` +Here is the output: + +```shell + Fetching data... + Data received! + Result: {'data': 42} +``` +In the Example: + +- `Async`: It is used to define an asynchronous function. +- `Asyncio`: It provides the framework and utilities to write asynchronous programs, such as event loops, tasks, and coroutines. + + +## Codebyte Example + +Below is another example: + +```codebyte/python +import asyncio + +async def greet(): + await asyncio.sleep(1) + return "Hello from await!" + +async def main(): + message = await greet() + print(message) + +asyncio.run(main()) +``` \ No newline at end of file From ab80a45684f0303071d1616fd76c5c7408dab9e8 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 16 Oct 2025 15:34:42 +0530 Subject: [PATCH 2/9] minor fixes with the content --- .../concepts/keywords/terms/await/await.md | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/content/python/concepts/keywords/terms/await/await.md b/content/python/concepts/keywords/terms/await/await.md index 6918b89b01a..c9c3d3e8925 100644 --- a/content/python/concepts/keywords/terms/await/await.md +++ b/content/python/concepts/keywords/terms/await/await.md @@ -1,19 +1,19 @@ --- Title: 'await' -Description: 'Pauses the execution of an async function until the awaited coroutine completes.' +Description: 'Suspends the execution of an asynchronous function until the awaited coroutine, task, or awaitable object finishes.' Subjects: - 'Computer Science' - 'Web Development' Tags: - - 'Async' - - 'Await' + - 'Async Await' + - 'Functions' - 'Python' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -The **`await`** keyword pauses the execution of an asynchronous function until the awaited [coroutine](https://docs.python.org/3/library/asyncio-task.html#id2), task, or awaitable object is completed. It allows asynchronous code to be written in a way that resembles synchronous code. +The **`await`** keyword suspends the execution of an asynchronous function until the awaited [coroutine](https://docs.python.org/3/library/asyncio-task.html#id2), task, or awaitable object completes. It allows asynchronous code to look and behave like synchronous code. ## Syntax @@ -21,54 +21,61 @@ The **`await`** keyword pauses the execution of an asynchronous function until t await expression ``` -The `await` keyword can only be used inside an `async` function. Using it outside an async function will raise a `SyntaxError`. +> **Note:** The `await` keyword can only be used inside an `async` function. Using it outside an async function will raise a `SyntaxError`. ## Example -The await keyword can be used to wait for an asynchronous task before continuing: +This example pauses execution while waiting for simulated data to be fetched: ```py import asyncio async def fetch_data(): - print("Fetching data...") - await asyncio.sleep(1) - print("Data received!") - return {"data": 42} + print("Fetching data...") + await asyncio.sleep(1) + print("Data received!") + return {"data": 42} async def main(): - result = await fetch_data() - print("Result:", result) + result = await fetch_data() + print("Result:", result) asyncio.run(main()) ``` + Here is the output: ```shell - Fetching data... - Data received! - Result: {'data': 42} +Fetching data... +Data received! +Result: {'data': 42} ``` -In the Example: -- `Async`: It is used to define an asynchronous function. -- `Asyncio`: It provides the framework and utilities to write asynchronous programs, such as event loops, tasks, and coroutines. +In this example: +- `async` defines an asynchronous function that can contain `await`. +- `asyncio` provides tools for running asynchronous code, such as event loops, coroutines, and tasks. -## Codebyte Example +## Example -Below is another example: +This example waits for one second before returning and printing a message: -```codebyte/python +```py import asyncio async def greet(): - await asyncio.sleep(1) - return "Hello from await!" + await asyncio.sleep(1) + return "Hello from await!" async def main(): - message = await greet() - print(message) + message = await greet() + print(message) asyncio.run(main()) -``` \ No newline at end of file +``` + +The output of this code is: + +```shell +Hello from await! +``` From 26357ac6e78e5cb0edff0de992b471764dcdeb66 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 16 Oct 2025 15:35:13 +0530 Subject: [PATCH 3/9] Update await.md --- content/python/concepts/keywords/terms/await/await.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/python/concepts/keywords/terms/await/await.md b/content/python/concepts/keywords/terms/await/await.md index c9c3d3e8925..82556c0fa05 100644 --- a/content/python/concepts/keywords/terms/await/await.md +++ b/content/python/concepts/keywords/terms/await/await.md @@ -23,7 +23,7 @@ await expression > **Note:** The `await` keyword can only be used inside an `async` function. Using it outside an async function will raise a `SyntaxError`. -## Example +## Example 1 This example pauses execution while waiting for simulated data to be fetched: @@ -56,7 +56,7 @@ In this example: - `async` defines an asynchronous function that can contain `await`. - `asyncio` provides tools for running asynchronous code, such as event loops, coroutines, and tasks. -## Example +## Example 2 This example waits for one second before returning and printing a message: From d87012795161c079efd87a80c0a65b2998ae20c3 Mon Sep 17 00:00:00 2001 From: Radhika-okhade Date: Wed, 22 Oct 2025 15:45:46 +0530 Subject: [PATCH 4/9] Update content/python/concepts/keywords/terms/await/await.md --- content/python/concepts/keywords/terms/await/await.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/python/concepts/keywords/terms/await/await.md b/content/python/concepts/keywords/terms/await/await.md index 82556c0fa05..f77e91d3cdf 100644 --- a/content/python/concepts/keywords/terms/await/await.md +++ b/content/python/concepts/keywords/terms/await/await.md @@ -13,7 +13,7 @@ CatalogContent: - 'paths/computer-science' --- -The **`await`** keyword suspends the execution of an asynchronous function until the awaited [coroutine](https://docs.python.org/3/library/asyncio-task.html#id2), task, or awaitable object completes. It allows asynchronous code to look and behave like synchronous code. +The **`await`** keyword pauses the execution of an asynchronous function until the awaited [coroutine](https://docs.python.org/3/library/asyncio-task.html#id2), task, or awaitable object completes. It lets asynchronous code read and behave more like synchronous code. ## Syntax From 0b42d4cb6ef12ac8f46c2b1e55e8a4cd61121f20 Mon Sep 17 00:00:00 2001 From: Radhika-okhade Date: Wed, 22 Oct 2025 15:45:53 +0530 Subject: [PATCH 5/9] Update content/python/concepts/keywords/terms/await/await.md --- content/python/concepts/keywords/terms/await/await.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/python/concepts/keywords/terms/await/await.md b/content/python/concepts/keywords/terms/await/await.md index f77e91d3cdf..72dbcb611c1 100644 --- a/content/python/concepts/keywords/terms/await/await.md +++ b/content/python/concepts/keywords/terms/await/await.md @@ -1,6 +1,6 @@ --- Title: 'await' -Description: 'Suspends the execution of an asynchronous function until the awaited coroutine, task, or awaitable object finishes.' +Description: 'Pauses the execution of an asynchronous function until the awaited coroutine, task, or awaitable object finishes.' Subjects: - 'Computer Science' - 'Web Development' From cdb60cc5ed522411112a95524bb20c247b0804e1 Mon Sep 17 00:00:00 2001 From: Anshusinghh Date: Thu, 23 Oct 2025 01:54:09 +0530 Subject: [PATCH 6/9] [Concept Entry] JavaScript: Destructuring #7759 --- .../concepts/destructuring/destructuring.md | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 content/javascript/concepts/destructuring/destructuring.md diff --git a/content/javascript/concepts/destructuring/destructuring.md b/content/javascript/concepts/destructuring/destructuring.md new file mode 100644 index 00000000000..acf2f144ad9 --- /dev/null +++ b/content/javascript/concepts/destructuring/destructuring.md @@ -0,0 +1,92 @@ +--- +Title: 'Destructuring' +Description: 'Destructuring is a convenient way to extract values from arrays or properties from objects into distinct variables.' +Subjects: +  - 'Web Development' +  - 'Computer Science' +Tags: +  - 'Destructuring' +  - 'Objects' +  - 'Arrays' +  - 'JavaScript' +CatalogContent: +  - 'introduction-to-javascript' +  - 'paths/front-end-engineer-career-path' +--- + +A _destructuring assignment_ allows you to unpack values from arrays or properties from objects directly into _distinct_ variables. This feature makes it easier to work with data, especially when handling complex objects or arrays. + +## Array Destructuring + +Array destructuring extracts values from arrays in order, assigning them to variables in a single statement. + +```js +const colors = ['red', 'green', 'blue']; +const [firstColor, secondColor, thirdColor] = colors; + +console.log(firstColor); // Output: red +console.log(secondColor); // Output: green +console.log(thirdColor); // Output: blue +``` + +You can also skip items you don’t need: + +```js +const [primaryColor, , tertiaryColor] = colors; +console.log(tertiaryColor); // Output: blue +``` + +## Object Destructuring + +Object destructuring allows you to extract specific properties using their key names: + +```js +const car = { make: 'Toyota', model: 'Camry', year: 2021 }; +const { make, model } = car; + +console.log(make); // Output: Toyota +console.log(model); // Output: Camry +``` + +You can also rename variables or assign default values: + +```js +const { model: carModel, color = 'white' } = car; +console.log(carModel); // Output: Camry +console.log(color); // Output: white +``` + + +## Nested Destructuring + +Destructuring supports nested structures for deeply nested objects or arrays: + +```js +const user = { +id: 1, +info: { name: 'Alice', address: { city: 'Seattle', zip: 98101 } } +}; + +const { info: { name, address: { city } } } = user; +console.log(name); // Output: Alice +console.log(city); // Output: Seattle +``` + +## Codebyte Example + +The following codebyte example uses nested destructuring to extract values directly from an object. + +```codebyte/js +const user = { + name: 'John Doe', + hobbies: ['reading', 'cycling', 'coding'], + address: { city: 'New York', zip: 10001 } +}; + +const { name, hobbies: [firstHobby], address: { city } } = user; + +console.log(`${name} enjoys ${firstHobby} in ${city}.`); +// Output: John Doe enjoys reading in New York. +``` + + From 493d8c832bbbd85cbffd3677e17a38b9e19a64df Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 28 Oct 2025 16:06:52 +0530 Subject: [PATCH 7/9] Revise destructuring.md for clarity and detail Updated the description of destructuring to clarify its purpose and added more detailed explanations throughout the document. --- .../concepts/destructuring/destructuring.md | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/content/javascript/concepts/destructuring/destructuring.md b/content/javascript/concepts/destructuring/destructuring.md index acf2f144ad9..75a554f1e08 100644 --- a/content/javascript/concepts/destructuring/destructuring.md +++ b/content/javascript/concepts/destructuring/destructuring.md @@ -1,35 +1,43 @@ --- Title: 'Destructuring' -Description: 'Destructuring is a convenient way to extract values from arrays or properties from objects into distinct variables.' +Description: 'Destructuring in JavaScript extracts values from arrays or properties from objects and assigns them to variables in a single, concise statement.' Subjects: -  - 'Web Development' -  - 'Computer Science' + - 'Computer Science' + - 'Web Development' Tags: -  - 'Destructuring' -  - 'Objects' -  - 'Arrays' -  - 'JavaScript' + - 'Arrays' + - 'Destructuring' + - 'JavaScript' + - 'Objects' CatalogContent: -  - 'introduction-to-javascript' -  - 'paths/front-end-engineer-career-path' + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' --- -A _destructuring assignment_ allows you to unpack values from arrays or properties from objects directly into _distinct_ variables. This feature makes it easier to work with data, especially when handling complex objects or arrays. +**Destructuring** in JavaScript extracts values from [arrays](https://www.codecademy.com/resources/docs/javascript/arrays) or properties from [objects](https://www.codecademy.com/resources/docs/javascript/objects) and assigns them to [variables](https://www.codecademy.com/resources/docs/javascript/variables) in a single, concise statement. It simplifies working with complex arrays and objects by reducing repetitive code. ## Array Destructuring -Array destructuring extracts values from arrays in order, assigning them to variables in a single statement. +Array destructuring extracts values from arrays in order, assigning them to variables in a single statement: ```js const colors = ['red', 'green', 'blue']; const [firstColor, secondColor, thirdColor] = colors; -console.log(firstColor); // Output: red -console.log(secondColor); // Output: green -console.log(thirdColor); // Output: blue +console.log(firstColor); +console.log(secondColor); +console.log(thirdColor); ``` -You can also skip items you don’t need: +The output for this is: + +```shell +red +green +blue +``` + +Items that aren’t needed can also be skipped: ```js const [primaryColor, , tertiaryColor] = colors; @@ -38,7 +46,7 @@ console.log(tertiaryColor); // Output: blue ## Object Destructuring -Object destructuring allows you to extract specific properties using their key names: +Object destructuring extracts specific properties from an object using their key names: ```js const car = { make: 'Toyota', model: 'Camry', year: 2021 }; @@ -48,7 +56,14 @@ console.log(make); // Output: Toyota console.log(model); // Output: Camry ``` -You can also rename variables or assign default values: +The output for this code is: + +```shell +Toyota +Camry +``` + +Variables can also be renamed or assigned default values: ```js const { model: carModel, color = 'white' } = car; @@ -56,10 +71,9 @@ console.log(carModel); // Output: Camry console.log(color); // Output: white ``` - ## Nested Destructuring -Destructuring supports nested structures for deeply nested objects or arrays: +Destructuring also supports nested structures for deeply nested objects or arrays: ```js const user = { @@ -68,13 +82,20 @@ info: { name: 'Alice', address: { city: 'Seattle', zip: 98101 } } }; const { info: { name, address: { city } } } = user; -console.log(name); // Output: Alice -console.log(city); // Output: Seattle +console.log(name); +console.log(city); +``` + +The output of this code is: + +```shell +Alice +Seattle ``` ## Codebyte Example -The following codebyte example uses nested destructuring to extract values directly from an object. +The following codebyte example uses nested destructuring to extract values directly from an object: ```codebyte/js const user = { @@ -86,7 +107,4 @@ const user = { const { name, hobbies: [firstHobby], address: { city } } = user; console.log(`${name} enjoys ${firstHobby} in ${city}.`); -// Output: John Doe enjoys reading in New York. ``` - - From c53355231a08888c0106289819ca1cb48c0e2b7e Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Fri, 31 Oct 2025 16:10:09 +0530 Subject: [PATCH 8/9] Minor changes --- .../concepts/destructuring/destructuring.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/content/javascript/concepts/destructuring/destructuring.md b/content/javascript/concepts/destructuring/destructuring.md index 75a554f1e08..c7954d9d51e 100644 --- a/content/javascript/concepts/destructuring/destructuring.md +++ b/content/javascript/concepts/destructuring/destructuring.md @@ -40,7 +40,9 @@ blue Items that aren’t needed can also be skipped: ```js +const colors = ['red', 'green', 'blue']; const [primaryColor, , tertiaryColor] = colors; + console.log(tertiaryColor); // Output: blue ``` @@ -66,7 +68,9 @@ Camry Variables can also be renamed or assigned default values: ```js +const car = { make: 'Toyota', model: 'Camry', year: 2021 }; const { model: carModel, color = 'white' } = car; + console.log(carModel); // Output: Camry console.log(color); // Output: white ``` @@ -77,11 +81,17 @@ Destructuring also supports nested structures for deeply nested objects or array ```js const user = { -id: 1, -info: { name: 'Alice', address: { city: 'Seattle', zip: 98101 } } + id: 1, + info: { name: 'Alice', address: { city: 'Seattle', zip: 98101 } }, }; -const { info: { name, address: { city } } } = user; +const { + info: { + name, + address: { city }, + }, +} = user; + console.log(name); console.log(city); ``` @@ -97,7 +107,7 @@ Seattle The following codebyte example uses nested destructuring to extract values directly from an object: -```codebyte/js +```codebyte/javascript const user = { name: 'John Doe', hobbies: ['reading', 'cycling', 'coding'], From aebd3c011020c2b7c24998e0ab6ff3c83f72316f Mon Sep 17 00:00:00 2001 From: Anshusinghh Date: Sat, 1 Nov 2025 01:11:58 +0530 Subject: [PATCH 9/9] [Term Entry] PyTorch Tensor Operations: .logical_xor() #7787 --- .../terms/logical-xor/logical-xor.md | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/logical-xor/logical-xor.md diff --git a/content/pytorch/concepts/tensor-operations/terms/logical-xor/logical-xor.md b/content/pytorch/concepts/tensor-operations/terms/logical-xor/logical-xor.md new file mode 100644 index 00000000000..64369428209 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/logical-xor/logical-xor.md @@ -0,0 +1,82 @@ +--- +Title: '.logical_xor()' +Description: 'Performs element-wise logical exclusive OR (XOR) operation on boolean tensors, returning a tensor where each element is `True` if the corresponding elements of the inputs differ, and `False` otherwise.' +Subjects: + - 'AI' + - 'Computer Science' + - 'Data Science' + - 'Machine Learning' +Tags: + - 'Booleans' + - 'Functions' + - 'PyTorch' + - 'Tensor' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/data-science' +--- + +In PyTorch, the **`.logical_xor()`** function performs an element-wise **logical exclusive OR (XOR)** operation between two tensors. It returns a new tensor where each element is `True` if exactly one of the corresponding elements in the input tensors is `True`, and `False` otherwise. + +For non-boolean tensors, zeros are treated as `False` and non-zeros as `True`. This operation is often used in conditions involving mutually exclusive logic or binary masking. + +## Syntax + +```pseudo +torch.logical_xor(input, other, *, out=None) +``` + +**Parameters:** + +- `input`: The first input tensor (boolean or numeric). +- `other`: The second input tensor (boolean or numeric). Must be broadcastable to the shape of `input`. +- `out` (Optional): A tensor to store the result. It must have the same shape as the output. The dtype is typically `torch.bool`, but integer types (like `torch.int16`) are also supported to represent `0` and `1`. + +**Return value:** + +Returns a tensor containing the element-wise logical XOR of the two input tensors. + +## Example + +The following example demonstrates the use of `.logical_xor()` for boolean and numeric tensors: + +```py +import torch + +# Boolean tensors +a = torch.tensor([True, False, True, False]) +b = torch.tensor([True, True, False, False]) + +# Element-wise logical XOR +res = torch.logical_xor(a, b) + +print('a:', a) +print('b:', b) +print('logical_xor(a, b):', res) + +# Numeric tensors — zeros are False, non-zeros are True +x = torch.tensor([0, 1, 2, 0]) +y = torch.tensor([1, 0, 2, 0]) + +print('\nx:', x) +print('y:', y) +print('logical_xor(x, y):', torch.logical_xor(x, y)) + +# Using an integer out tensor (int16) to store 0/1 results +out_buf = torch.empty(4, dtype=torch.int16) +torch.logical_xor(x, y, out=out_buf) +print('\nlogical_xor(x, y) with out=int16:', out_buf) +``` + +The above code produces the following output: + +```shell +a: tensor([ True, False, True, False]) +b: tensor([ True, True, False, False]) +logical_xor(a, b): tensor([False, True, True, False]) + +x: tensor([0, 1, 2, 0]) +y: tensor([1, 0, 2, 0]) +logical_xor(x, y): tensor([ True, True, False, False]) +logical_xor(x, y) with out=int16: tensor([1, 1, 0, 0], dtype=torch.int16) +```