Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Strings
Index -> Programming, Python -> Python Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Sniper4Life




PostPosted: 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
Sponsor
sponsor
Alexmula




PostPosted: 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 Laughing
Sniper4Life




PostPosted: 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




PostPosted: Wed Apr 15, 2009 9:58 pm   Post subject: RE:Strings

Can you get what users type into a string?
Sniper4Life




PostPosted: 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




PostPosted: Thu Apr 16, 2009 12:45 pm   Post subject: RE:Strings

A string is a string is a string.
Sniper4Life




PostPosted: Thu Apr 16, 2009 3:00 pm   Post subject: RE:Strings

sigh just nvr mind...i dont even understand what i want answered Sad
cus i understand all of the things i listed

but i just dont understand...how to manipulate...the user input...
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Dusk Eagle




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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 Embarassed i dont even know what those u's represent Laughing Embarassed anyone care to explain?
Dusk Eagle




PostPosted: Thu Apr 16, 2009 7:52 pm   Post subject: Re: Strings

That's funny, I don't get that. Are you using CPython?
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: