Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Can This Be Used?
#1
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
Code:
print "duck"
So how would it be useful?
Reply
#2
maybe if you could describe where it came from. etc.. i could prob help.
Reply
#3
It didnt come from anywhere. To be more specific how does x.replace come in use
Reply
#4
(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
Reply
#5
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.
Reply
#6
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..
Reply
#7
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 :].
[Image: izsyo6.jpg]


Reply
#8
to replace certain characters in an unkown variable, not everything is staticaly typed
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)