Posts

Showing posts from June, 2025

[Python] Understanding the sorted() Function in Python — Guide and Examples

Hello, this is BlockDMask. Today we’ll explore Python’s built-in sorted() function, which lets you sort any iterable and return a new list. If you’re looking for the list.sort() method instead, check out [this post on list.sort()] . <Table of Contents> What is sorted()? Example 1: Sorting a List of Numbers Example 2: Sorting Strings Case-Insensitive Example 3: Sorting Tuples by Second Element Example 4: Sorting Dictionary Keys and Items Example 5: Sorting Dictionary by Value Bonus Tip: Sorting Custom Objects 1. What is sorted()? The sorted() function takes any iterable—like a list, tuple, string, or dict—and returns a new, sorted list : sorted(iterable) sorted(iterable, reverse=True) sorted(iterable, key=func) sorted(iterable, key=func, reverse=True) iterable : any object you can loop over (list, tuple, string, dict). key : a function that extracts a comparison key from each element. reverse : False for ascending (default), True ...

[Python] 3 Ways to Limit Decimal Places in Python (With Examples)

Hello, this is BlockDMask. In this post, we'll explore how to control the number of decimal places in Python. Whether you're formatting prices, displaying percentages, or rounding calculations — precision matters. <Table of Contents> Using the round() function Using the format() function Using f-strings 💡Bonus Tip: Using decimal for accurate rounding 1. Using the round() Function The round() function is the most basic way to round a number to a certain number of decimal places. It takes two arguments: the number to round, and the number of decimal places. price1 = round(19.8765) # 20 price2 = round(19.8765, 0) # 20.0 price3 = round(19.8765, 1) # 19.9 price4 = round(19.8765, 2) # 19.88 price5 = round(19.8765, 3) # 19.877 print(f"Rounded (no decimal): {price1}") print(f"Rounded (0 decimals): {price2}") print(f"Rounded (1 decimal): {price3}") print(f"Rounded (2 decimal...

[Python] How to Use the sort() Function in Python with Examples

Hello, this is BlockDMask. Today, we’ll take a deep look at how to use the sort() method in Python to sort a list. We’ll cover ascending and descending sorting, and clarify the difference between sort() and sorted() . <Table of Contents> How the sort() method works in Python Ascending and descending sort with reverse parameter Difference between sort() and sorted() 1. How the sort() method works in Python 1-1) Basic usage of sort() The list.sort() method directly modifies the original list in place. It does not return a new list. This method is only available for list objects. Note: If you want to sort something without changing the original list, use sorted() instead. We'll cover that later. 1-2) sort() examples with numbers and strings # Sorting numbers temperatures = [86, 74, 90, 61, 79, 68] print("1. Sorted temperatures:") temperatures.sort() print(temperatures) # Sorting strings (lowercase only) cities = ['chicago', ...

C memcpy() Function Explained with Examples (Beginner Friendly)

Hello, this is BlockDMask. Today, we will learn how to use the memcpy() function in C/C++ to copy memory contents from one place to another. Now, let’s dive into how memcpy() works, with practical examples and some important things to watch out for. Table of Contents 1. What is memcpy()? 2. memcpy example with int array 3. memcpy example with partial string copy 4. memcpy example with full string copy (critical point) 5. Extra example: memcpy with structure ✅ 1. What is memcpy()? The function name memcpy comes from "memory copy". As the name suggests, it copies a block of memory from a source to a destination in raw bytes. Header files: In C: <string.h> In C++: <cstring> Function prototype: void* memcpy(void* dest, const void* source, size_t num); Parameters: dest : Pointer to the destination memory block source : Pointer to the source memory block num : Number of bytes to copy In short, memcpy(dest, sou...

How to View Saved Wi-Fi Password on Windows (Step-by-Step Guide)

Hello, this is BlockDMask. Today, we’ll learn how to recover the Wi-Fi password for networks you've previously connected to in Windows . Have you ever needed to connect a phone, tablet, or new laptop to your Wi-Fi, but couldn’t recall the password? If your computer has connected to the network before, Windows may have saved the password — and you can retrieve it easily! Let’s go through two simple ways to find your Wi-Fi password. Table of Contents 1. Retrieve Wi-Fi password using Command Prompt 2. Retrieve Wi-Fi password using Control Panel 3. How to change your Wi-Fi password ✅ Method 1: Retrieve Wi-Fi password using Command Prompt Press Windows Key + R to open the Run dialog. Type cmd and press Enter to open Command Prompt. In the command window, type the following command: netsh wlan show profiles This command lists all wireless networks your computer has connected to before. Find the profile name (SSID) of the network you want to che...

How to Check Your IP Address in Windows (Private IP & Public IP explained)

Hello, this is BlockDMask. Today, we'll learn how to check your computer's IP address in Windows — both your private (internal) IP and public (external) IP. If you’ve ever worked with remote access, routers, VPNs, or server setups, you’ve probably heard of "IP addresses." Fortunately, checking your IP is very easy, and it's useful in many situations. Table of Contents 1. How to check your Private IP (Internal IP) 2. How to check your Public IP (External IP) 3. Why do you need to check your IP address? ✅ How to check your Private IP address (inside your local network) This is the IP address assigned to your computer by your router, usually in a home or office network. Other devices on the same Wi-Fi network have similar addresses. 📌 Method 1: Using Command Prompt (cmd) Press Windows Key + R to open the Run window. Type cmd and press Enter. In the black command window, type: ipconfig You’ll see detailed network informat...

Python isdigit() Explained: Check if a String Contains Only Digits (with examples)

Hello, this is BlockDMask. Today, we will explore how to check whether a string contains only digits in Python using the isdigit() method. This is very useful when you're validating user input, processing files, or scraping web data where numeric checks are needed. Table of Contents 1. What is isdigit() in Python? 2. Limitations and common pitfalls of isdigit() 3. Practical examples of isdigit() 4. Difference between isdigit(), isdecimal(), and isnumeric() 1. What is isdigit() in Python? The isdigit() method checks if a string contains only numeric digits (0–9). It belongs to the string class and can be used like this: str.isdigit() Basic behavior: Returns True if all characters are digits (0-9) Returns False if any non-digit character exists Signs like - (negative) or . (decimal) make it return False Certain Unicode numeric characters may return True (e.g. superscripts, fractions) Typically used for checking whether user inpu...

Python: Convert List to String (join & for loop methods explained)

Hello, this is BlockDMask. Today, we will learn how to convert a Python list into a string . We will cover: Lists with only strings Lists containing both strings and numbers How to use both join() and for loop methods Table of Contents 1. Convert list to string using join() 2. Convert list to string using for loop 1. Convert list to string using join() The easiest way to convert a list of strings into a single string is by using Python’s join() method. 1-1) Simple join() fruits = ['apple', 'banana', 'cherry', 'date', 'BlockDMask'] result = ''.join(fruits) print(result) Output: applebananacherrydateBlockDMask 1-2) Add separator while joining fruits = ['apple', 'banana', 'cherry', 'date', 'BlockDMask'] result_comma = ', '.join(fruits) print(result_comma) result_dash = ' - '.join(fruits) print(result_dash) result_newline = '\n'...

C memset() Function Explained with Examples (Beginner-Friendly Guide)

Hello, this is BlockDMask. Today, we will learn about one of the most essential memory manipulation functions in C and C++: memset() . It is commonly used for array initialization and filling memory blocks with a specific value. Table of Contents 1. What is memset()? 2. Example 1: Modify part of a string 3. Example 2: Array initialization (for loop vs memset) 4. Example 3: Be careful when setting non-zero values 5. Example 4: Quickly resetting structures ✅ 1. What is memset()? The memset() function allows you to fill a memory block with a specific value for a specified size (in bytes). The name is very intuitive: memory + set → set memory . Here’s the function prototype: void* memset(void* ptr, int value, size_t num); ptr : Pointer to the start of the memory block to fill value : The value to fill with (automatically cast to unsigned char ) num : Number of bytes to fill Even though value is declared as int , internally it stores only 1...

Windows Shutdown and Reboot Using Command Prompt (shutdown command guide)

Image
Hello, this is BlockDMask. Today, let’s learn how to shutdown or reboot your Windows computer using Command Prompt (cmd) directly. Normally, you click on the shutdown or restart buttons. But sometimes, command-line control is helpful: You want to shutdown or restart after N seconds automatically. You are accessing a remote or restricted computer where GUI buttons are not available. Table of Contents 1. How to Open Command Prompt 2. Shutdown Command Options Explained 3. Practical Shutdown and Reboot Examples 1. How to Open Command Prompt Option 1: Press Windows Key → Search for cmd and open it. Option 2: Press Windows + R → In the "Run" box, type cmd and press Enter. 2. Shutdown Command Options Explained You can type shutdown /? in cmd to display full documentation of available options. Basic command format: shutdown [options] Common options: /s : Shutdown the computer /r : Restart (shutdown and reboot) /p : Force shutdow...

Python None vs Null vs is None vs == Comparison Explained

Hello, this is BlockDMask. Today, let’s clearly explain some of the most confusing concepts in Python: None, null, empty string (""), 0, False, [], {} , and the difference between the comparison operators is and == . Many beginners get confused when to use is None vs == None , and how Python treats different "empty" values. Let’s break it down step-by-step with simple and practical examples. Table of Contents 1. Python null is None 2. Difference: None, 0, "", [], {}, False 3. is vs == comparison 4. How to properly check for None 5. Using None as default argument in functions 6. Difference: None vs Empty String 7. Summary Table 1. Python null is None response = None print(response) Output: None → In Python, there’s no null . Instead, we use None to represent "no value" or "nothing exists". 2. Difference: None, 0, "", [], {}, False Python considers all of these as False i...

How to Convert and Check String Case in Python (upper, lower, isupper, islower)

Hello, this is BlockDMask. Today, we’ll cover how to convert strings to uppercase or lowercase in Python, as well as how to check if a string is uppercase or lowercase. 1. Convert string to uppercase - upper() method The upper() method converts all alphabetic characters in the string to uppercase. The original string is not modified; it returns a new string. Basic syntax: string.upper() # string: the target string object # return: new string converted to uppercase Examples & Results: # Example 1 name = 'BlockDMask' upper_name = name.upper() print('name :', name) print('upper_name :', upper_name) # Output: # name : BlockDMask # upper_name : BLOCKDMASK → The original string remains unchanged; a new uppercase string is returned. # Example 2 word = 'PyThOnIsFun'.upper() print('word :', word) # Output: # word : PYTHONISFUN → Mixed-case letters are all converted to uppercase. # Example 3 (reassigning to same variable) c...

How to Write Comments in Python (Single-line, Multi-line, Shortcuts & Indentation Tips)

Hello, this is BlockDMask. Today, we’re going to learn how to write comments in Python . Python supports both single-line and multi-line comments. You can freely use them depending on the situation. Did you know that some Python comments require proper indentation? I once struggled with PyCharm due to indentation issues in comments, so I’m writing this post to help you avoid the same mistake. 1. Types of Comments in Python ▶ Single-line Comment: # Single-line comments start with the # symbol. Example 1 - Comment on an empty line # This is a single-line comment example 1 def comment_example(): print("Comment example. DMask") Typically, one space is added after the # symbol before writing the comment. Example 2 - Comment at the end of a line def comment_example(): print("Comment example. Mask") # This is single-line comment example 2 ▶ Multi-line Comment: Triple Quotes """ or ''' Multi-line comment...

Python split() Function: Usage and Examples

Hello, this is BlockDMask . Today, we’ll learn about the split() function in Python. This function is commonly used to split a string into a list using a specified delimiter. Let’s explore how it works with some practical examples. 📚 Table of Contents What is the split() function? Examples of using split() 1. What is the split() function? Function Syntax: string.split() string.split('delimiter') string.split('delimiter', maxsplit) string.split(sep='delimiter', maxsplit=n) The split() function divides a string into parts based on a separator and returns a list of those parts. More formally: string.split(sep, maxsplit) It splits the string using the specified sep (separator) up to maxsplit times and returns a list. 🔸 sep parameter Default is None , which splits on whitespace and newline characters Example: string.split(sep=',') splits on comma Short form: string.split(',') is also valid 🔸 max...

5 Ways to Take a Screenshot on Windows (Full Guide)

Hi, this is BlockDMask . Today, I’ll show you 5 different ways to take a screenshot in Windows , including useful shortcuts that will make your workflow much faster. 1. PrtSc (Print Screen) Press PrtSc key → Entire screen is copied to clipboard. Paste it into Paint, Word, or Photoshop using Ctrl + V . 📝 Simple, but doesn't save the image automatically. 2. Alt + PrtSc Captures only the active window . Paste with Ctrl + V in any editing tool. 📝 Great when you don’t want the full screen. 3. Windows + Shift + S (Snip & Sketch) Opens Snipping Tool overlay with area selection. Options: Rectangle, Freeform, Window, Fullscreen. Image is saved to clipboard + small notification popup for editing. 📝 Highly flexible and quick. My personal favorite! 4. Windows + PrtSc Takes a full-screen screenshot and automatically saves it . Saved to: This PC > Pictures > Screenshots 📝 Best for bulk captures or tutorials. 5. Snippin...