Home » Programming

Rounding Numbers Up with the PHP ceil() Function, with Examples

PHP ceil()

This short tutorial will cover how to use the PHP ceil() function to round numbers UP – and provide some code examples. The PHP ceil() function rounds a number up (and only up!) to the nearest integer. To round a number down to the nearest integer, use the floor() function instead. To round a number normally, or for more options when rounding a number, use the round() function. PHP ceil() Function Syntax The syntax for the PHP ceil() function is as follows: ceil($NUMBER) Note that: $NUMBER is the float or integer number you wish to perform the ceil() operation on ceil() will return a float type number regardless of … Read more

Categories PHP

Home » Programming

How to Use the PHP ‘while’ Loop, With Examples

PHP while

This tutorial will teach you how to use the while statement to build loops in the PHP programming language and show some examples. The while loop is the most straightforward kind of loop in PHP. The code inside the loop will execute for as long as the while condition is true. Change the condition, and the loop will exit. while loops are a fundamental part of PHP (and loops are an essential part of computer programming in general) – so it’s good to know how they work and what they can be … Read more

Categories PHP

Home » Programming

How to Use the PHP ‘do while’ Loop, With Examples

PHP do while

This tutorial will teach you how to use the do while statement to build loops in the PHP programming language, and show some examples. The do while loop is one of the simplest types of loop in PHP. The code inside the loop will execute for as long as the do while condition is true. Change the condition, and the loop will exit. do while loops are a fundamental part of PHP (and loops are an essential part of computer programming in general) – so it’s good to get to know how they … Read more

Categories PHP

Home » Programming

How to Use the Python slice() Function, With Examples

Python slice()

The Python slice() function can be used to get a portion of a list, tuple, string, or other sequence. This article will show you how to use it. Python slice() Function Syntax Here’s the syntax for the Python slice() function: slice(START, STOP, STEP) Note that: slice() does not return the specified portion of an object It returns a slice object which is used to retrieve the specified portion from a sequence – it does not contain the sequence itself. This is probably best demonstrated in the below examples START is the starting position (index) of the sequence you … Read more

Home » Programming

What is a Python Dictionary? Explanation and Code Examples

Python dictionary

Here’s everything you need to know about the Dictionary data type in Python, what it can store, and how to use it. Python has several built-in data types for storing data (more than other languages like JavaScript) – from basic types like integers, floating-point numbers, and strings to more complex types like lists, tuples, and dictionaries. What is a Type? A variable’s type defines what kind of value it can store and what can be done with it. What is a Dictionary? A dictionary is a variable type … Read more

Home » Programming

How to Add/Append Items to a Dictionary in Python [Examples]

Add Item to Python Dictionary

This short tutorial will show you how to add single or multiple items (as key:value pairs) to a dictionary in the Python programming language. What is a Dictionary in Python? We’ve covered what dictionaries are in our article here. There are a couple of ways to add items to a dictionary, so we’ve put together this article separately to make sure we’ve got everything covered! Checking Whether a Key Exists in a Dictionary As outlined in the article linked above, dictionaries store data as a series of key:value pairs. Before … Read more

Home » Programming

How to Merge Dictionaries in Python, With Examples

Python Merge Dictionaries

This article will show you the simplest ways to merge two or more dictionaries in the Python programming language. Note that the code examples in this article are written for Python version 3 – and will not work with Python version 2! What is a Dictionary in Python? We’ve covered what dictionaries are in our article here. As there are a couple of ways to merge multiple dictionaries in Python, we’ve put together this article separately to make sure we’ve got everything covered! Merging/Joining Using Dictionary Union … Read more

Home » Programming

The Python ord() Function – What it Does and How to Use It

Python ord()

The ord() function returns an integer representation of a Unicode character. Here’s why it does that and how it’s used. Python ord() Function Syntax First, here’s the syntax for the ord() function: ord(CHAR) Note that: CHAR is the single Unicode character you wish to receive the corresponding integer representation of Only a single character is allowed! OK, But Why? The integer returned by ord() is the Unicode code point of the character. It’s a unique number that identifies the character. Unicode represents characters from several languages and includes symbols, emojis, and combinations of all of them. When data is saved … Read more

Home » Programming

How to Slice a Dictionary in Python, With Examples

Python Dictionary slice()

We’ve covered how to use the slice function to slice strings, tuples, lists, and other sequences. This tutorial will show you how to slice dictionaries, with examples. Dictionaries Not sure what a dictionary is in the Python programming language? Get up to speed with our article here. The slice() Function and the islice() Function Check out the full article here on how the slice() function works – we’ve covered it in-depth. Unfortunately, the slice() function built-in to Python does not work with dictionaries. If you do try to use slice() with a dictionary type variable, you will receive the following error: TypeError: … Read more

Home » Programming

How to use Comments in JavaScript

JavaScript Comments

This short article will explain how and why you should use comments in JavaScript. First up, how to comment. What is a Comment? A comment in programing is one or more lines of text that aren’t interpreted as programming instructions. Instead, the computer skips them when executing your code, completely ignoring them. Therefore, comments don’t have to conform to any valid syntax. They’re just text that you read, and the computer doesn’t. Single-Line Comments in JavaScript Commenting is easy. How easy? This easy: // This is a comment … Read more