Python is an object-oriented programming language ideally designed for rapid prototyping of complex applications. Like Perl, Python source code is also available under the GNU General Public License (GPL).

In this article we will see how to How to use Python Strings: Replace, Join, Split, Reverse with example.

1) Strings in python can be accessed as array of character:


name = 'Te3chburps';
print name[0]

Output: Output will be something like this:

T


2) [ : ] Range slice-it gives the characters from the given range in a python string:


name = 'Te3chburps';
print name[0:3]

Output: Output will be something like this:

Te3


3) "in" and "not in" to check if an input sequence is present in a python string:


name = 'Te3chburps';
print '3' in name
print 'as' in name

print '3'  not in name
print 'ch' not in name

Output: Output will be something like this:

True
False
False
False


4) Concatenate (+) and repeat (*) in a python string:


name = 'Te3chburps';
print name+name
print name*3

Output: Output will be something like this:

Te3chburpsTe3chburps
Te3chburpsTe3chburpsTe3chburps


5) 'replace() Method in a python string:


name = 'Te3chburps';

print name;
name = name.replace('3','4');
print name;

Output: Output will be something like this:

Te3chburps
Te4chburps


6) Upper case (upper(),capitalize()) and Lowercase (lower()) in a python string:


name = 'tbNext';

print name.upper();
print name.capitalize();
print name.lower();

Output: Output will be something like this:

tbNext
tbNext
tbNext


7) Join and Split a String in python:


name = 'TEC Hbur ps';

print ":".join(name)	
print name.split(' ');

Output: Output will be something like this:

T:E:C: :H:b:u:r: :p:s
['TEC', 'Hbur', 'ps']


In this article we have seen, How to use Python Strings: Replace, Join, Split, Reverse with example. In upcoming articles we will see more complex usecases and tricks of python.
  • By Techburps.com
  • Sep 30, 2017
  • Python