Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>> str = "hello" >>> str += " there bear" >>> str 'hello there bear' >>> # we can index strings. >>> mystring = "Computer Science" >>> mystring 'Computer Science' >>> mystring[0] 'C' >>> mystring[5] 't' # Note that mystring[8] is a blank; that's why we can't see it >>> print(mystring[0],mystring[5],mystring[8]) C t # You can't access elements that don't exist! >>> mystring[100] Traceback (most recent call last): File "", line 1, in mystring[100] IndexError: string index out of range >>> mystring[-4] 'e' >>> # how do i print the last character of a string? >>> mystring 'Computer Science' >>> len(mystring) 16 >>> mystring 'Computer Science' >>> len([1,2,3]) 3 >>> len(mystring) 16 >>> mystring = 'hello' >>> len(mystring) 5 >>> # a general statment for printing the last element of mystring >>> print(mystring[len(mystring)-1]) o >>> mystring = "Computer Science" >>> print(mystring[len(mystring)-1]) e >>> mystring 'Computer Science' # The index has to be an int; a float does not make sense >>> mystring[1.2] Traceback (most recent call last): File "", line 1, in mystring[1.2] TypeError: string indices must be integers >>> ## Next BIG topic >>> ## loops other than for loops >>> ## while condition >>> ## body #### Next topic (a short one) >>> ## just a short hand >>> ## easy >>> count = 0 >>> count = count + 1 >>> count += 1 >>> count 2 >>> count += 55 >>> count 57 >>> count -= 5 >>> count 52 >>> count -= 2 >>> count 50 >>> count *= 3 >>> count 150 >>> # x op= y >>> # does that make sense? Yes, iff the following makes sense >>> # x = x op y >>> "bw" + "ha" * 44 'bwhahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha' >>> str = 'ha' >>> >>> st = 'ha' >>> st = st * 4 >>> st 'hahahaha' >>> st = 'ha' >>> st *= 4 >>> st 'hahahaha'