strings.org
author Puneeth Chaganti <punchagan@gmail.com>
Wed, 21 Apr 2010 15:12:08 +0530
changeset 96 3498d74ed615
parent 95 fddcfd83e4f0
child 97 25248b12f6e4
permissions -rw-r--r--
Changed outline of strings.org.

* Strings
*** Outline
***** Strings
******* basic manipulation
******* operations
******* immutability
******* string methods
******* split and join
******* formatting - printf style
***** Odds and Ends
******* dynamic typing
******* comments
***** Simple IO
******* raw_input
******* console output
***** Arsenal Required
******* lists
******* writing to files
*** Script
    Welcome friends. 
    
    In this tutorial we shall look at data types available in Python and 
    how to perform simple Input and Output operations. 
    for 'Numbers' we have: int, float, complex datatypes
    for Text content we have strings.
    For conditional statements, 'Booleans'.
    
    Now we shall look at Python Strings.
    In python anything enclosed inside quotes(single or double) is a string
    so 
    a = 'This is a string'
    print a
    b = "This too!"
    print b
    c = '''This one too!'''
    print c
    d = """And one more."""
    print d
    
    Similar to lists we covered earlier even string elements can be accessed 
    via index numbers starting from 0

    print a[0]    
    print a[5]
    will 
    To access last element we can use a[-1] which is one of Pythons feature.
    print a[-1]
    len function works with the strings also as it does with the arrays and 
    returns length of the string.
    
    One thing to notice about the string variables is that they are 
    immutable, that is
    a[0] = 't'
    will throw an error
    
    Some of methods available for string are:
    a.startswith('Thi')
    returns true if initial of the string is same
    similarly there is endswith
    a.endswith('ING')
    a.upper() returns a string with all letters capitalized.
    and a.lower() returns a string with all smaller case letters.
    As we have seen earlier use of split function, it returns the list after
    splitting the string, so
    a.split()
    will give list with three elements.
    we also have 'join' function, which does the opposite of what
    split does. 
    ''.join(['a','b','c']) will return a joined string of the list we pass
    to it. Since join is performed on '' that is empty string we get 'abc'
    if we do something like
    '-'.join(['a','b','c'])
    
    we come to the end of this tutorial on introduction of Data types in
    Python. In this tutorial we have learnt what are supported data types, 
    supported operations and performing simple IO operations in Python.

*** Notes