Home » Search results for 'python string'

Read a File Line by Line in Python [3 Methods]

Line by Line in Python

This tutorial will examine several methods and best practices for reading a file line-by-line in the Python programming language. Reading a file line-by-line will be useful for parsing log files, CSV spreadsheet files, or even reading files you have generated from an application yourself. Line by Line File Reading – Examples The examples on this page will read from a text file named mytext.txt with the following content: Linux Is Very Cool Using the readlines() Function The following python code will call the built-in open() function, which … Read more

Home » Search results for 'python string'

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 » Search results for 'python string'

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 » Search results for 'python string'

PHP strpos Function: Check if a String Contains Another String

php strpos function

The PHP strpos() function checks whether a string is contained within another string – for example checking whether a certain word appears in a sentence, and what position it appears in.  It is a great companion to the PHP substr() and str_replace() functions for processing text data. Syntax strpos ( $haystack , $needle [, $offset = 0 ] ) Note that: $haystack is the string (text or series of characters) we want to search within $needle is the string search term we are looking for $offset Is optional … Read more

Categories PHP

Home » Search results for 'python string'

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

Home » Search results for 'python string'

How to Reverse a List in Python

How to Reverse a List in Python

Even outside of programming, people perform list reversal regularly, for example, to re-order eBay items from high to low then low to high. It is a handy operation, and Python provides several ways to accomplish it. Method 1: Using the built-in reverse() function This method has the advantage of being simple and easy to understand when using someone else’s code. For example, if we have stored our list in “staffNames”: staffNames = [“Abigail”, “Chris”, “Denise”, “Fred”] staffNames.reverse() When executed, this method doesn’t automatically give a … Read more

Home » Search results for 'python string'

Escape Characters in Python, With Examples

Escape Characters in Python

Every programming language has special characters that trigger certain behaviors in your code – and Python is no exception. These characters cannot be used in strings (as they are reserved for use in your code) – and must be “escaped” to tell the computer that the character should just be treated as a regular piece of text rather than something that needs to be considered while the code is being executed. If you want to be able to leave yourself notes in your code, check … Read more

Home » Search results for 'python string'

How to Make Multiline Comments in Python

How to make multi line comments in Python

In this tutorial, we explain the two methods used to make multiline comments in Python, with examples. There are some drawbacks to one of the methods, so pay attention. Code without comments is like a story written in a language you only half understand. You might be able to figure out the main points, but you’ll miss some nuances and it would be way easier with a translation alongside it. Most coders hate code with no comments or limited comments, so finding ways to clearly … Read more

Home » Search results for 'python string'

Python: How to Check Whether a File or Directory Exists

Python How to check whether a file or directory exists

In this article, we explain how to check whether a file or directory exists in Python and include some useful examples to help you get started. Python is a high-level programming language with dynamic semantics. Developed in the early 90s, and named after the Monty Python comedy troupe, it uses simple, easy-to-learn syntax and remains very popular amongst the programming community. It is particularly attractive for Rapid Application Development (RAD) and for its ability to connect existing components together. Python can be used for: server-side … Read more

Home » Search results for 'python string'

JavaScript Reference: Complete List of Operators + Examples

JavaScript Operators

This article will explain and list JavaScript operators and expressions. JavaScript operators perform a given operation on the provided expressions or values. Common operations include comparisons, arithmetic, and ternary operations. You will use JavaScript operators frequently (even the simplest JavaScript code will use multiple operators!), so it’s worth getting to know them, and their expected behaviour. What are Operators and Operands? Javascript operators perform a given operation, for example addition, subtraction, and other arithmetic, comparisons like greater than/less than, and more complicated operations like ternary/comparison … Read more