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
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
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
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
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
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
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 ?
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