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