How would can you put this code to use?
Code:
x = "luck"
#replace the l in in luck with a d
y = x.replace("l", "d")
#Displays what y is equal to on the screen
print y
There is the code, but im thinking, why not just
So how would it be useful?
maybe if you could describe where it came from. etc.. i could prob help.
It didnt come from anywhere. To be more specific how does x.replace come in use
(10-16-2009, 06:57 PM)nevets04 Wrote: [ -> ]It didnt come from anywhere. To be more specific how does x.replace come in use
Since Python is also good for web development, I think it can be used like PHP functions str_replace() or preg_replace(), for example bbCode to HTML
Im a noob in python, but maybe a text encrypter, you could set it if there is an a then make it a c. Like this -
text = raw_input()
text = text.replace("a", "1")
text = text.replace("b", "2")
/There may be an easier way to do that but keep going a - z
print "Encrypted text is " text
/Now just reverse that so they can decrypt text.
I dont know if this helped or how well this will work but it is just a suggestion.
The replace code can be used to scramble words if you do not want others to understand some words.. In other words, to hide the real message.. using print = "duck" is of no use if the user sees the source code and not just the viewable program..
Well, it can be used for many things but is most useful for website developers handling large documents. One example is when xhtml came about and people wanted to convert from html to xhtml. The following quotes are from
www.w3schools.com
"A general "find-and-replace" function was executed to replace all uppercase tags with lowercase tags. The same was done for attribute names."
"Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.
A general "find-and-replace" function was executed to swap the tags."
hope this helped :].
to replace certain characters in an unkown variable, not everything is staticaly typed