Python String to Float – A Simple Illustrated Guide

Summary: To convert a string object to float object use the float(string_input) method which typecasts the string input to a floating-point value. Introduction Before learning how to convert a string object to a float object, let us understand what is type conversion in Python. ✎ The process of converting an object of a particular data … Read more

How to Escape Special Characters of a Python String with a Single Backslash?

The backslash escape character ‘\’ is a special Python string character that is usually followed by an alphabetic character. For example, the tabular whitespace ‘\t’ and newline ‘\n’. In regular expressions, you can use the single escape to remove the special meaning of regex symbols. For example, to match the dot or asterisk characters ‘.’ … Read more

Python String zfill()

Fills the string from the left with “0” characters. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.zfill(width) Fills the string from the left with “0” characters. width – the length of the resulting string. Although it works for … Read more

Python String upper()

Returns an uppercase string version. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.upper() Returns an uppercase string version (copy) whereas each character is replaced with its uppercase variant: Application String Upper – Ignoring String Case An application of … Read more

Python String translate()

Returns a translated string. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.translate(table) Returns a translated string that is a copy of the original string whereas only the character translations defined in the table argument have been applied to … Read more

Python String title()

Python’s built-in string.title() method returns a new string that has uppercase first characters for each word. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.title() Returns a new string with uppercase first characters of each word. πŸ’‘ Info: A … Read more

Python String swapcase()

Swaps lowercase to uppercase characters and vice versa. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.swapcase() Swaps lowercase to uppercase characters and vice versa. Note: Although you may expect that swapcase() is its own inverse function, this is … Read more

Python String strip()

Trims whitespaces on the left and right and returns a new string. Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.strip([chars]) Trims whitespaces on the left and right and returns a new string. chars – optional. The argument defines … Read more

Python String startswith()

Returns whether the string starts with a given value or not (True or False). Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.startswith(prefix[, start[, end]]) Returns whether the string ends with a given value or not (True or False). … Read more

Python String splitlines()

Splits the string at line breaks such as ‘\n’ and returns a split list of substrings (i.e., lines). Minimal Example As you read over the explanations below, feel free to watch our video guide about this particular string method: Syntax and Explanation str.splitlines([keepends]) Splits the string at line breaks such as ‘\n’ and returns a … Read more