Author |
Message |
Sniper4Life

|
Posted: Wed Apr 15, 2009 6:35 pm Post subject: Strings |
|
|
Could someone give me tutorial on the following subjects in pythong: ????
- Slices
- Escape sequences
- len()
- String Methods
? upper
? lower
? find
? replace
? count
Then I would like to know ALL ways you can manipulate a user's input.
ok also...when you have a string like "My foot" they are 2 seperate strings under one function or w/e...and is there any way
to program in python...so that the computer can identify WHERE the space is...when print the words out seperately? so what im basically asking for this question is how do you slice a user's input? like make the output come out SLICED |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Alexmula
|
Posted: Wed Apr 15, 2009 8:44 pm Post subject: RE:Strings |
|
|
look up the string module. and you can split "my foot" with the split function  |
|
|
|
|
 |
Sniper4Life

|
Posted: Wed Apr 15, 2009 9:15 pm Post subject: RE:Strings |
|
|
yes i know that but what im trying to say is can you do that WITH user input?
like split w/e they type? |
|
|
|
|
 |
wtd
|
Posted: Wed Apr 15, 2009 9:58 pm Post subject: RE:Strings |
|
|
Can you get what users type into a string? |
|
|
|
|
 |
Sniper4Life

|
Posted: Thu Apr 16, 2009 7:19 am Post subject: RE:Strings |
|
|
yes they need to write their fulll name so (First name) (Last name)
but every time...the number of characters can be different but it is only 2 words under one raw input every time
but i dont know how to slice that string
cus its user input |
|
|
|
|
 |
wtd
|
Posted: Thu Apr 16, 2009 12:45 pm Post subject: RE:Strings |
|
|
A string is a string is a string. |
|
|
|
|
 |
Sniper4Life

|
Posted: Thu Apr 16, 2009 3:00 pm Post subject: RE:Strings |
|
|
sigh just nvr mind...i dont even understand what i want answered
cus i understand all of the things i listed
but i just dont understand...how to manipulate...the user input... |
|
|
|
|
 |
Tony

|
Posted: Thu Apr 16, 2009 3:07 pm Post subject: RE:Strings |
|
|
re-read this entire thread from the start. Your answer is in here already. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
Dusk Eagle

|
Posted: Thu Apr 16, 2009 3:23 pm Post subject: Re: Strings |
|
|
You're not manipulating anything while the user is entering input. But, once the user has entered input, is there any difference between a string generated like this:
Python: |
string = raw_input()
|
and a string generated like this:
Python: |
string = "John Doe"
|
|
|
|
|
|
 |
Sniper4Life

|
Posted: Thu Apr 16, 2009 4:41 pm Post subject: Re: Strings |
|
|
ok this is basically what its like
code: |
string = raw_input ("Please enter your full name")
|
the user can now enter ANY name
now
code: |
what would i enter here...so that W/E they inserted...can be split?
|
and yes dusk there is
because raw input could be any name
it isnt nessessarily going to be John Doe
so...how can you make it so that you can split a string...without knowing what the string will be? but it has 2 words and 1 space in between it...??? |
|
|
|
|
 |
Dusk Eagle

|
Posted: Thu Apr 16, 2009 6:02 pm Post subject: Re: Strings |
|
|
Python: |
namelength = 2 #Number of names we want (In this case, 2, as we just want a first and last name)
num_words = namelength + 1
while num_words > namelength:
string = raw_input("Enter your name: ")
string = string.split()
num_words = len(string)
print "out of loop"
|
Is this what you're looking for? |
|
|
|
|
 |
Alexmula
|
Posted: Thu Apr 16, 2009 6:55 pm Post subject: RE:Strings |
|
|
i believe this is what he means
Python: |
name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName
|
|
|
|
|
|
 |
Dusk Eagle

|
Posted: Thu Apr 16, 2009 7:07 pm Post subject: Re: RE:Strings |
|
|
Alexmula @ Thu Apr 16, 2009 7:55 pm wrote: i believe this is what he means
Python: |
name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName
|
That's basically what I did, except my code checks to make sure the user has only entered two words, and no more. (It doesn't check if the user entered less than two words, but that's easily fixable.) I have a question about your code though. What is name = str(name) supposed to do? I believe raw_input() automatically treats input as a string. |
|
|
|
|
 |
Alexmula
|
Posted: Thu Apr 16, 2009 7:13 pm Post subject: Re: RE:Strings |
|
|
Dusk Eagle @ Thu Apr 16, 2009 7:07 pm wrote: Alexmula @ Thu Apr 16, 2009 7:55 pm wrote: i believe this is what he means
Python: |
name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName
|
That's basically what I did, except my code checks to make sure the user has only entered two words, and no more. (It doesn't check if the user entered less than two words, but that's easily fixable.) I have a question about your code though. What is name = str(name) supposed to do? I believe raw_input() automatically treats input as a string.
if you dont put that then some u's appear beside the names i dont even know what those u's represent anyone care to explain? |
|
|
|
|
 |
Dusk Eagle

|
Posted: Thu Apr 16, 2009 7:52 pm Post subject: Re: Strings |
|
|
That's funny, I don't get that. Are you using CPython? |
|
|
|
|
 |
|