Advertisement
Mars83

6-6

Oct 9th, 2011
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. #! /usr/bin/env python3.2
  2. # -*- coding: utf-8 -*-
  3.  
  4. # main.py
  5. """ Task: Exercise 6.6
  6.    Read the documentation of the string methods at
  7.    docs.python.org/lib/string-methods.html. You might want to experiment with
  8.    some of them to make sure you understand how they work. strip and replace
  9.    are particularly useful. The documentation uses a syntax that might be
  10.    confusing. For example, in find(sub[, start[, end]]), the brackets indicate
  11.    optional arguments. So sub is required, but start is optional, and if you
  12.    include start, then end is optional.
  13. """
  14.  
  15. ''' Main '''
  16. string = 'X-DSPAM-Confidence: 0.8475'
  17. stringReplace = string.replace('-', '_', 1) #: 'X_DSPAM-Confidence: 0.8475'
  18. stringReplace = string.replace('Z', '_')    #: 'X-DSPAM-Confidence: 0.8475'
  19. stringReplace = string.replace(0, 1)    #: TypeError
  20. stringFind = string.find('e')   #: 14
  21. stringFind = string.find('e', 15)   #: 17
  22. stringFind = string.find('e', 18, 3000) #: -1 = not found
  23. stringFind = string.find('e', 18, 14)    #: -1
  24. stringFind = string.find('e', -1)   #: -1
  25. stringFind = string.find(8)   #: TypeError
  26. print(stringReplace)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement