Code in Python
Your How-to Guide

String Manipulation in Python

25th May 2017

The code snippet below shows how to work with strings in Python. Learn various string manipulation methods. Learn about various operations you can perform on strings like splicing astring, reverse string, change case, etc. Refer the code snippet below.

# strings
# double and single quotes use in Python
"hey there! welcome to CIP"   
'hey there! welcome to CIP'  
"you'll understand python"          
'i said, "python is awesome!"'      
'i can\'t live without python'      
# use of 'r' before string
print(r"\new code", "\n")    

first = "code in"
last = "python"
first + last     #concatenation

# slicing of strings

user = "code in python!"

print(user[5])   # print an element 
print(user[-3])  # print an element from rear end
print(user[2:6]) # slicing the string
print(len(user))   # length of the string
print(user.upper()) # convert to uppercase
print(max(user)) # max alphabet from user string
print(min(user)) # min alphabet from user string


About Author

Akarsh Singh

Developer, Tech. Evangalist, Loves to read and write about new tech. Madly in love with Python. Follow him on social media.

1. For more Awesome ads-free content help me to stay awake late. Buy me a coffee.

2. Want to know where Code in Python website is hosted. Buy cheapest Web hosting (less than 1.5$/month or Rs.99/month) using this referral link. This is trusted and tested web hosting service Code in Python relies on.

backupWeb hosting
3. Support Akarsh Singh(Founder, Code in Python) so that he can teach you more Python and Machine Learning Concepts for free. Contribute to his page and he will mention you in his next post.

4. Indian Users can donate through Paytm.