Title: String Operations
Slug: string_operations
Summary: String Operations
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon
Python 3 has three string types
In [1]:
string = 'The quick brown fox jumped over the lazy brown bear.'
In [2]:
string_capitalized = string.capitalize()
string_capitalized
Out[2]:
In [3]:
string_centered = string.center(79, '.')
string_centered
Out[3]:
In [4]:
string_counted = string.count('e', 4, len(string))
string_counted
Out[4]:
In [5]:
string_find = string.find('e', 4, len(string))
string_find
Out[5]:
In [6]:
string_isalpha = string.isalpha()
string_isalpha
Out[6]:
In [7]:
string_isdigit = string.isdigit()
string_isdigit
Out[7]:
In [8]:
string_islower = string.islower()
string_islower
Out[8]:
In [9]:
string_isalnum = string.isalnum()
string_isalnum
Out[9]:
In [10]:
string_isalnum = string.isspace()
string_isalnum
Out[10]:
In [11]:
string_istitle = string.istitle()
string_istitle
Out[11]:
In [12]:
string_isupper = string.isupper()
string_isupper
Out[12]:
In [13]:
len(string)
Out[13]:
In [14]:
string_lower = string.lower()
string_lower
Out[14]:
In [15]:
string_upper = string.upper()
string_upper
Out[15]:
In [16]:
string_title = string.title()
string_title
Out[16]:
In [17]:
string_swapcase = string.swapcase()
string_swapcase
Out[17]:
In [18]:
string_lstrip = string.lstrip()
string_lstrip
Out[18]:
In [19]:
string_strip = string.strip()
string_strip
Out[19]:
In [20]:
string_rstrip = string.rstrip()
string_rstrip
Out[20]:
In [21]:
string_replace = string.replace('e', 'E', 4)
string_replace
Out[21]: