Home » Programming

How to Reverse a List in Python

How to Reverse a List in Python

Even outside of programming, people perform list reversal regularly, for example, to re-order eBay items from high to low then low to high. It is a handy operation, and Python provides several ways to accomplish it. Method 1: Using the built-in reverse() function This method has the advantage of being simple and easy to understand when using someone else’s code. For example, if we have stored our list in “staffNames”: staffNames = [“Abigail”, “Chris”, “Denise”, “Fred”] staffNames.reverse() When executed, this method doesn’t automatically give a … Read more

Home » Programming

PHP ‘str_replace’ Function: Find and Replace Text

php str_replace function

The PHP str_replace() function replaces words or sections (known as substrings) in a string with other words or sentences, allowing you to modify or reformat text values (find and replace text). Syntax str_replace ( $search , $replace , $subject [, &$count ] ) Note that: $search is the string value being searched for – it can even be an array of strings if you wish to search for multiple values $replace is the value you wish to replace the $search value with – it can also be an array if … Read more

Categories PHP

Home » Programming

Using the PHP ‘explode’ Function (With Examples)

php explode function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP explode function is vital for processing user input. It takes a string (a series of characters) and splits it up into smaller strings by a given delimiter to specify the boundary of where the splits should occur. Syntax explode ( $delimiter , $string [, $limit ] ) Note that: $delimiter … Read more

Categories PHP

Home » Programming

Using the PHP ‘substr’ Function (With Examples)

Using the PHP 'substr' Function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP substr function takes a string (a series of characters) and returns only the specified portion of it. Syntax substr ( $string , $start [, $length ] ) Note that: The function returns either the specified portion of the given $string (even if it’s empty) as a new string … Read more

Categories PHP

Home » Programming

Python Find in List: Check if an Element is Present

python find in list

Python offers several different types of arrays for storing data. Lists are arrays which allow you to store items. These list items can be altered, and are stored in a specific order. There are several methods you should consider for searching a list in Python– searching for a specific value match, or searching for list items that match a certain condition or set of conditions. You can also remove items from a list in Python. Checking if a List Contains an Item Using the ‘in’ … Read more

Home » Programming

Concatenating (Joining) Strings in Python

string concatenation python

Let’s look at two ways you can concatenate (which is a fancy word for join or merge) two or more strings in Python. It’s also worth checking out our article on converting integers to strings in Python. A Note On Immutable Strings Strings in Python are immutable and cannot be changed once defined. This means that whenever you join two strings, a new string is created (ie. the original is not modified!). This has both performance side effects and affects how you should structure your code: … Read more

Home » Programming

Escape Characters in Python, With Examples

Escape Characters in Python

Every programming language has special characters that trigger certain behaviors in your code – and Python is no exception. These characters cannot be used in strings (as they are reserved for use in your code) – and must be “escaped” to tell the computer that the character should just be treated as a regular piece of text rather than something that needs to be considered while the code is being executed. If you want to be able to leave yourself notes in your code, check … Read more

Home » Programming

Measuring the Length of a String in JavaScript, with Examples

Measuring the Length of a String in JavaScript, with Examples

In this guide, we explain how to measure the length of a string in JavaScript using the length method. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and is perfect for learning tools like Node.js … Read more

Home » Programming

Check Array Contains a Value in JavaScript, with Examples

Determining Whether an Array Contains a Value

This tutorial will show you how to check whether an array contains a specific value in Javascript, with full examples. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and is perfect for learning tools like … Read more

Home » Programming

Removing an Element From an Array in JavaScript, with Examples

Removing an Element From an Array in JavaScript

There are multiple ways to remove an element from an array in Javascript. We cover all of the methods that can be used in this tutorial. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and … Read more