Roshan Book

My Tech Notebook

Python tutorial 13–Strings


Common methods :

#string.upper() – This will change everything to upper case
#’This is a string {}’.format(42) –  will publish This is a string 42
# s.capitalize()- Publish in sentence case
#s.lower()
#s.swapcase() -opposite case
# s.find(‘is’) – returns the postion
#s.replace(‘This’,’That’) – This is entirely dirreferen objetc that returns
#s.strip()- this removes white space from beginning and end
#s.rstrip() – removes white space from end of string
#s1.rstri(‘n’)- takes out only new line
#s.isalnum()-if checks it has only alphanumeric charactures
#s.isalpha()-checks only for alpha charcters, like a to z onle
#s.isdigit()- checks if only digit
#s.isprintable()- checks if all characters are printable

 

Format method

#s=”this is {},that is {}”.format(a,b)
#now you can do s.format(d,e) and this geenrates a new objetc which youc an save in a different vairable

# You can also specify as ‘this is {1} and that is {0}’.format(a,b))
# this will print this is b and that is a
# you can also use dictionary to rpint than postion like ‘this is {bob} and that is {fred}’.format(bob=a,fred=b)
# another way is to define dictionaly first d=dict(bob=a, fred=b) and then use ‘this is {bob} and that is {fred}’.format(**d)

# Splitting and joining stings
s= ‘This is string a strng of words’
#s.split() splits depending on white space i.e. [“This”,’is’,’string’,’of’,’words’
                                               
# to specify argument to splits
#words=split(‘i’)  # this gives strings with all i removed and words splitter on i character
#    joining   
# ‘,’join(words) # This will join back all the words
                           
# docs for string methods : http://docs.python.org/py3k/library/stdtypes.html#string-methods
# Python full library at http://docs.python.org/py3k/library/

3 responses to “Python tutorial 13–Strings

  1. Devin October 17, 2011 at 11:50 pm

    Thanks for your post. What I want to comment on is that when searching for a good on the internet electronics retail outlet, look for a website with complete information on critical indicators such as the level of privacy statement, basic safety details, payment procedures, along with other terms in addition to policies. Always take time to browse the help as well as FAQ segments to get a better idea of what sort of shop works, what they are able to do for you, and the way you can make best use of the features.

  2. louis vuitton wallets December 5, 2011 at 6:22 am

    Can you tell me how I can add your weblog to my news reader. your help are appreciated I want to access your articles.

  3. Discount LV Handbags December 5, 2011 at 5:24 pm

    I went over this web site and I believe you have a lot of wonderful info, saved to my bookmarks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: