Sling Academy
Home/Python/Page 74

Python

Python: 4 Ways to Declare a Multiline String (Block String)

Updated: May 25, 2023
This concise, straight-to-the-point article shows you a couple of different ways to declare a multiline string (block string) in Python. Using Triple Quotes (Recommended) You can use triple quotes (""" or ''') to declare multiline......

The modern Python regular expressions cheat sheet

Updated: May 25, 2023
This page provides a comprehensive, example-style cheat sheet about regular expressions in Python. I myself use it quite regularly in my work. You can bookmark it to quickly look up as needed. Note that you always have to import the re......

Python: Converting a string to lowercase/uppercase

Updated: May 25, 2023
In Python, you can use the str.lower() and str.upper() methods to change the case of all characters in a string to lowercase or uppercase, respectively. These methods have been part of the programming language for almost two decades. They......

Python: 5 ways to check if a string contains a substring

Updated: May 25, 2023
This succinct, practical article will walk you through several different ways to check whether a string contains a specific substring in Python. I assume you already have some basic understanding of the programming language, so I......

Python: 4 Ways to Convert a String into a List

Updated: May 25, 2023
This concise, example-based article walks you through four different ways to turn a given string into a list in Python. Life is short, and time is precious; let’s get to the point. Using the str.split() method f you want to......
Python String Slicing: Tutorial & Examples

Python String Slicing: Tutorial & Examples

Updated: May 24, 2023
Overview In Python, string slicing allows you to extract specific portions, or substrings, from a string by specifying the start and end indices. Syntax: string[start:end:step] Where: start is the index indicating......

Python: 5 Ways to Reverse a String

Updated: May 24, 2023
When writing code with Python, there might be cases where you need to reverse a string, such as when you want to check if a string is a palindrome ( a word or phrase that is the same when read forward or backward) or perform some......

Python: Remove leading/trailing whitespace from a string

Updated: May 24, 2023
This concise, straightforward article will show you a couple of different ways to trim leading and trailing whitespace from a given string in Python. Overview You can skip this section and move on to the next one if you’re in......
4 Ways to Format a String in Modern Python

4 Ways to Format a String in Modern Python

Updated: May 24, 2023
Using f-strings or formatted string literals (Python 3.6+) This method allows you to embed variables and expressions directly into string literals by prefixing the string with f (that’s why the term f-strings was born).......

The modern Python strings cheat sheet

Updated: May 24, 2023
This page provides a comprehensive, example-style cheat sheet about strings in modern Python (Python 3.10 and newer versions). I also use it quite often for quick lookups when building projects. You can bookmark it as a handy reference......
Python: 7 Ways to Find the Length of a String

Python: 7 Ways to Find the Length of a String

Updated: May 24, 2023
This concise, example-based article will walk you through several different ways to find the length (the number of characters) of a given string in Python. Each approach will be explained briefly, followed by a code example. I assume that......

Python: Extract and download all images from a web page

Updated: May 20, 2023
This example-based article walks you through 2 different ways to programmatically extract and download all images from a web page with Python. The first approach use requests and beautifulsoup4, while the second one uses scrapy. Using......