Home » Programming

How to Calculate Natural Logs/Logarithms (ln) in Python

Python calculate natural log:logarithm

This article will show you how to calculate natural logs/logarithms in the Python programming language, with examples. What is a Natural Log/Logarithm (ln)? A number’s natural logarithm is it’s logarithm to the base of e. It’s a bit more advanced than the usual arithmetic you’re probably used to seeing as you learn to program, so here’s a bit of explanation: A logarithm is the reverse of an exponent. The logarithm of a number is the exponent that another number must be raised to to produce the first number. You’re … Read more

Home » Programming

How to use the Python sum() Function to Add/Sum Numbers

Python sum

The Python sum() function takes a list of numbers, and sums them up (totals/adds them all together). Here’s how to use it, with examples. Summing/Totalling/Adding Numbers The concept of summing numbers is simple – take the numbers you wish to get the total of, and add them all together. 1 + 2 + 3 = 6 It’s basic arithmetic that you’ll use daily when writing computer software in any language. Summing Numbers in Python The sum() function in Python sums numbers. It’s a built-in function, which can be used anywhere … Read more

Home » Programming

How to Iterate/Loop over a Dictionary in Python [Examples]

Python iterate loop dictionary

This article will show you how to iterate/loop over the keys and values in a Python dictionary, and provide code examples. What is a Python Dictionary? In Python, a dictionary is a data type that contains a collection of objects – but unlike a list or array, rather than their values being recorded at a specific index (or ordered position in the sequence of stored values), they are stored in a key – a string identifier which both tells you what a value is for, and which … Read more

Home » Programming

Python hasattr() – What it Does and How to Use It [Examples]

Python use hasattr() to check object properties

The hasattr() function is used to check whether an object has a given named attribute. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Programming

How to Generate & Write CSV Files in Python, With Examples

Python write csv file

This article will show you how to generate CSV (Comma Separated Values) data, and write it to a file, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with … Read more

Home » Programming

Python – Concatenating Iterators With itertools.chain() [Examples]

Concatenate:join iterables using chain in Python

This tutorial will show you how to join/concatenate/merge iterables in the Python programming language, and provide code examples. What is an ‘Iterable’ in Python? An iterable is any kind of Python object that can return each of its members one at a time. Put simply, it’s any Python object that contains multiple values that can be looped over. Python’s built-in Iterables include lists, strings, and tuples — all object types which can be represented as a sequence of values. Iterating over Iterables To demonstrate this behaviour, we can create a list of strings, … Read more

Home » Programming

Python getattr() – What it Does and How to Use It [Examples]

Python use getattr() to get object attributes

The getattr() function is used to get the value of an attribute of an object. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Programming

How to Reverse a String in Python, With Code Examples

Python reverse string

This quick tutorial will show you how to reverse a string in Python, and provide example code. Strings in Python Strings in Python are defined using quotes or double quotes, and assigned to variables: string1 = “This is a string” string2 = ‘This is also a string’ Strings are used to store non-numeric values – things like names, words, sentences, and serialized data. There’s a lot you can do with Python strings. Strings are immutable — meaning that once defined, they cannot be changed. However, the variable holding … Read more

Home » Programming

LinuxScrew Guide for Developers Learning PostgreSQL

Learn PostgreSQL Guide

This page serves as the index for our PostgreSQL tutorials. It will be updated as new articles in the series are added. This guide is intended for developers who are just getting started with PostgreSQL and are looking for a simple resource to get them up and running. PostreSQL Guide Introduction: What is PostgreSQL? Why Use It ?

Home » Programming

PostreSQL Guide Introduction: What is PostgreSQL? Why Use It ?

PostgreSQL Introduction - What is PostgreSQL

This article is part of the LinuxScrew Guide for Developers Learning PostgreSQL. PostgreSQL is a relational database management system. It is similar to other networked SQL database servers like MySQL/MariaDB and Microsoft SQL, but there are some key differences in features and functionality. PostgreSQL vs Other Database Systems You can see a comparison of PostgreSQL and other database systems here. In short, while MySQL is the most popular open source database system, PostgreSQL is more advanced. PostgreSQL is object oriented, can store a larger number of types … Read more