## How to Calculate Median in Python (with Examples)

To calculate the median value in Python: For example, let’s calculate the median of a list of numbers: Output: The median value is a common way to measure the “centrality” of a dataset. If you are looking for a quick answer, I’m sure the above example will do. But to really learn what median really […]

## How to Limit Decimal Places in JavaScript

To limit decimal places in JavaScript, use the toFixed() method by specifying the number of decimal places. This method: For instance, let’s round to 2 decimals: Output: But this is just one way to do it. Also, it has some caveats. This is a comprehensive guide to rounding values in JavaScript. You will learn how

## Python What Does ‘u’ Mean in Front of a String

The ‘u’ in front of a string means the string is a Unicode string. A Unicode is a way for a string to represent more characters than a regular ASCII string can. In Python 2.x shell, you can see how for example a text written in Russian converts to a Unicode string with ‘u’ in

## How to Return Multiple Values from a Python Function

To return multiple values from a Python function, use a comma to separate the return values. For instance, let’s create a function that takes two numbers as arguments. This function returns the sum, difference, multiplication, and division between these two numbers. Here is how it looks in the code: Now you can call this function

## How to Filter an Array in Swift

To filter an array in Swift: For instance, let’s filter an array of words such that only words less than 4 characters long remain: Output: This is the quick answer. But to know how filtering really works in Swift, please read along. How to Filter an Array in Swift In the introduction, you saw a

## What Is a Final Class in Swift

You can use a final class in Swift to disable the inheritance of the class. For example, let’s create a class Student and make it a final class to disallow inheritance: If you now try to subclass this class, you are going to see a compile-time error: Output: This error says it is not possible

## What Is a Completion Handler in Swift

A completion handler in Swift is a function that calls back when a task completes. This is why it is also called a callback function. A callback function is passed as an argument into another function. When this function completes running a task, it executes the callback function. Example Here is a demonstrative (but not

## How to Read the Last Line of a File in Python

To read the last line of a file in Python without storing the entire file in memory: Here is an example: The Naive Approach The most naive approach to read the last line of a file in Python is: Here is the code: Find the Last Line of a Large File in Python If you

## Swift Check If an Array Contains an Object with Property

To check if a Swift array contains an object with a specific property: For instance, let’s find out if a student called Bob is in an array of students: To understand how this works and to get the context, please read along. Full Example with Context First of all, let’s give context to the above

## How to Get Current Time in Swift (Quick 3-Step Guide)

To get the current time in Swift: For example, let’s show what time it is right now in the console: Output: A Deeper Dive Let’s take a closer look at the above Swift code. This Swift code imports the Foundation framework, which provides fundamental data types, collections, and operating-system services to the Swift programming language.