A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.pythonforbeginners.com/basics/strings-built-in-methods/ below:

Strings Built-In Methods - PythonForBeginners.com

You are here:

Home / Basics /

Strings Built-In Methods

Strings Built-In Methods

Author: Last Updated: July 19, 2021

Strings Built-In Methods

In this post I want to show what you can do with the built-in methods for python Strings. Let’s first create a string with the value of “Hello World”

string = "Hello World"

To manipulate strings, we can use some of Pythons built-in methods

string.upper()   # get all-letters in uppercase

string.lower()    # get all-letters in lowercase

string.capitalize() # capitalize the first letter

string.title()    # capitalize the first letter of words

string.swapcase() # converts uppercase and lowercase

string.strip()    # remove all white spaces

string.lstrip()   # removes white space from left

string.rstrip()   # removes white space from right

string.split()    # splitting words

string.split(',') # split words by comma

string.count('l')   # count how many times l is in the string

string.find('Wo') # find the word Wo in the string

string.index("Wo")  # find the letters Wo in the string

":".join(string)  # add a : between every char

" ".join(string)  # add a white space between every char

len(string)   # find the length of the string

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Primary Sidebar

Get Our Free Guide To Learning Python


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4