Home » Programming » Python

COVID Vaccination Rate Notifier [Project] – Scraping and Displaying with Python

COVID Vaccination Rate Notifier

This article takes you through the creation of a COVID vaccination rate notifier. This project works by scraping data from the web and then displaying system notifications with Python. It hasn’t been the greatest year – but there’s light at the end of the tunnel. We’ve waited for the vaccine, and now we wait for people to get the vaccine. To keep sane through the winter, we’re all watching the vaccination rate slowly climb – hopefully to the point where we can go to the … Read more

Home » Programming » Python

Building a Python Script to Resize & Watermark Images [Code Included]

Building a Python Script to Resize Watermark Images

In this project, we take you through building, packaging, and publishing a command-line application using Python to resize and watermark images. Whenever I complete an article for LinuxScrew, I need to go through and add watermarks and make other small adjustments to any photos I’ve taken. This can be tedious so I thought, why not automate it. Then I thought, why not make a command-line app to do it (rather than just a bash script), and show you how you can make your own command-line … Read more

Home » Programming » Python

Python “while” Loops [with Examples]

python while loops

This tutorial explains how to create loops in Python by using the “while” statement. Included below are the syntax and examples. In programming (and thus, in Python), a loop is a statement which will execute a block of code repeatedly until a condition is met, or the loop is broken out of manually. This article will look at Python Loops and conventions to use when writing them. Looping with the while statement, Syntax and Example Here is a basic loop which will increment (add 1) the variable ‘i’ … Read more

Home » Programming » Python

Python time.sleep() to Pause, Sleep, Wait or Stop a Python Script

Pause Sleep Wait or Stop a Python Script

There is a useful function in Python called ‘sleep()’. It’s part of the ‘time’ module and allows you to pause, sleep, wait, or stop a Python script or application. Python can be used to make useful command-line tools to streamline your workflow, but sometimes you need to wait for the user, or for a pre-defined amount of time. For example, you may want to prompt the user to press a key when they have finished reading instructions or give them time to override a default … Read more

Home » Programming » Python

Python List ‘sort()’ Method – Sorting Lists in Python Easily

Sorting Lists in Python Easily

In Python, there’s an easy way to sort lists: using the sort() method. This tutorial explains how to use sort(), with examples. We’ve covered the following in Python: Removing list items Checking if items are in lists Finding items in lists Now it’s time to find out how to sort a list. Syntax for the sort() Method list.sort(reverse=True|False, key=sortFunction) Note that: ‘reverse’ should be a True/False boolean value and is optional reverse=True will sort the list descending The default is reverse=False True/False values case sensitive in Python! … Read more

Home » Programming » Python

Python: Find in a List and Return Values [using ‘filter’]

Python Find in a List and Return Values

This tutorial explains how to find items within a list in Python and return the values, using “filter”. Previously we covered checking whether items exist in a list in Python, but that could only tell us whether they were present, or not (with a boolean return value containing the result). If you are searching a list for a specific value, you already know what the value of the matching items will be so the above method is sufficient. However, what if you are searching by a set of … Read more

Home » Programming » Python

How to Install Pip/Pip3 for Python [Simple Guide]

How to Install Pip3

This tutorial will teach you how to install pip3, the package manager for Python, on Ubuntu Linux. Pip is a Python Package Manager. It’s currently at version 3 – hence, Pip3. Python is useful on its own, but it’s even more useful when you can start leveraging other people’s pre-written code. The default repository used by Pip is the Python Package Index (PyPI) (https://pypi.org/). PyPI contains a collection of other users’ code for performing a multitude of tasks, from drawing graphs to artificial intelligence. Checking if Pip is Already Installed … Read more

Home » Programming » Python

Boolean Operators: Comparing Values in Python

Boolean Operators in python

Python is widely used for both scripting and automation on Linux, as well as building web and standalone applications. Python is designed to be easy to learn, easy to write, and easy to read. It’s a great multi-purpose programming language. Boolean Values This article covers how boolean operators work in Python. In programming, a boolean value is either TRUE or FALSE. When comparing values in Python, a boolean value is returned allowing you to store the result of the comparison, or take a certain action … Read more

Home » Programming » Python

Check Python Version (Windows, Linux & macOS)

Check Python Version (Windows, Linux & macOS)

This tutorial explains how to check the version of Python that is installed on your system. The commands work on Windows, Linux & macOS, and with Python2 or Python3. Python is an incredibly popular and powerful programming language worldwide for everything from website development, content aggregation tools, link shortening, and writing scripts, to data analysis, virtual assistants, and machine learning. There are various versions available with different release dates, so how do you know which version is running on your machine? Here’s a quick guide … Read more

Home » Programming » Python

How to Get the Length of a List in Python

How to get the length of a list in Python

This tutorial will teach you how to find the length of a list (array) in Python using some code examples. There are four data structures built into Python: tuples, sets, dictionaries, and lists. They are important for programmers because they allow for iteration over their contents. When we talk about data structures such as lists in Python, we are referring to a collection data type. Lists in Python can be ordered and changed. Also, unlike the sets collection type, a list allows for duplicated entries, … Read more