Home » 2021

How to Generate Random Numbers and Strings in Python

Python Generate Random Strings Numbers

This article will outline several methods for generating random numbers and strings in the Python programming language. Generating random values is a common and important task when programming almost any kind of application of moderate complexity. Random strings and numbers are used to generate unique identifiers (e.g., for the short URLs in URL shortening services), for identifying unique records in a database, and (most importantly) are frequently used to determine the behavior of gameplay elements in video games (for example, simulating a coin flip, or … Read more

Home » 2021

Python: Calculating a Number’s Root (Square/sqrt, Cube), With Examples

Python Calculate Square Root

This article will show you how to calculate the square root, or any root, of numbers in the Python programming language. We previously covered squaring and raising numbers to a power in this article. What is a Root in Mathematics? The root of a number x is the number that must be multiplied by itself a given number of times to equal the number x. For example, the second root of 16 is 4 as 4*4 = 16. It is the second root because 4 must be multiplied by itself twice to reach the required result of 16. The third root of 64 is 4 as 4*4*4 = … Read more

Home » 2021

Best Way to Check if a File/Directory is Writable [Python]

Python - Check if File/Directory Writable

This quick tip will show you the best way to check if a file or directory is writable in the Python programming language. Python: The Best Way To Check if a File or Directory is Writable Just try and write to it. That’s it. If you can write to the file, it must be writable Try and write to it, and handle any failure which occurs. try: with open(‘newfile.txt’, ‘w’) as file file.write(‘hello!’) file.close() except IOError as error: # You could also catch Exception instead of IOError to … Read more

Home » 2021

How to Use if…else Conditional Statements in PHP [Examples]

PHP If...Else

Here’s a handy guide on using if/else/elseif conditional statements in PHP to execute code based on certain conditions. if/else statements are found in pretty much all programming languages. Computer programs need to perform actions based on a user selection, or the result of a calculation, or the value received from a sensor – and if/else statements are how this is programmed into the system. When building even the most basic programs, you’ll use them, so they’re worth getting to know. PHP Syntax There are several parts to an if … Read more

Categories PHP

Home » 2021

Appending Items to a List in Python with append() [Examples]

Python - Append to List

This article will show you how to add items to a list in Python using the append() method. Lists are a type of Python variable that can hold any number of member elements. They’re analogous to arrays in other programming languages. Lists can be defined and altered in several ways: Using the Python ‘filter()’ Function to Filter a List, with Examples Using the Python ‘map()’ Function to Process a List, With Examples Python List ‘sort()’ Method – Sorting Lists in Python Easily How to Reverse a List in … Read more

Home » 2021

How to Use the PHP echo Statement, With Examples

PHP echo

This quick tutorial will show you how to use the PHP echo statement to print/display information on screen. A computer program isn’t much good if it doesn’t display some output to the user. The echo statement prints a simple string of text in PHP – usually to the web browser. Syntax echo is a simple statement with a simple purpose – and it has simple syntax: echo expressions Note that: expressions should be one or more strings containing the text or characters you want to display on screen If more than … Read more

Categories PHP

Home » 2021

Limit Column Values With The MySQL CHECK Constraint [Examples]

MySQL CHECK CONSTRAINT

This article will demonstrate the usage of the SQL CHECK Constraint to limit column values, as used in MySQL/MariaDB. The SQL CHECK constraint allows you to define limitations to the value which can appear in a table column. It also allows you to apply constraints to a whole table, letting you restrict a column’s values based on the values of other columns in the table row. This behavior is useful for making sure you are only getting valid data inserted into your database. For example, you might … Read more

Home » 2021

Default MySQL/MariaDB Port, Finding It, Changing It

Changing the MySQL Port

This article will show you how to find the default or current MySQL (or MariaDB) port and how to change it. What is a Port? A port is a numerical identifier for a communication endpoint on a computer network. Or, put simpler, it’s a unique number on your computer that points to a specific program that is running so that other programs can connect to it. MySQL/Maria DB, being networked database services, expose themselves to other computers via a configured port, allowing other computers to connect to and … Read more

Home » 2021

How to Use the which Command in Linux, With Examples

Linux which Command

This tutorial will teach you how to use the which command in Linux with some simple examples. The which command will tell you the path to the executable used by a command on the system if it exists. Why is this useful? Say you’ve got two copies of the MySQL executable installed on your system (installed via different means), and you want to know which one is actually in use so that the other can be removed – the which command can tell you which of the two is called when you execute MySQL on … Read more

Home » 2021

How to Set/Change the Date/Time in Linux

Linux set time

This simple tutorial will show you how to view, set, or update the time and date on your Linux system. You may also want to check out our article on changing the timezone in Linux. Find out the Current Time and Date Before you change the time and date, it’s worth checking what it’s currently set to – it may already be correct! The following command will display information about the time and timezone as it is currently set on your system: timedatectl The returned … Read more