Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

minimallinux

Can we use 'input' instead of 'raw_input', I tried 2.6 and 3.3 versions and 'input' seems to work on both. Just a thought

  • one year ago
  • one year ago

  • This Question is Closed
  1. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 1

    Of course you can. The only difference is that by using raw_input you are always getting a string value as an input which you must convert/cast to the required type. Also, I believe that raw_input does not exist in Python v3.x. It has been renamed to input(). The following are true for Python v2.x. On the other hand input will evaluate whatever you pass in. So if you pass in a number (and the input function can understand that it is a number) you will get an int value back, where with raw_input you would get a string representation of the int value. Therefore, if you pass the number 3 to input function, you will get back the int 3. If you pass the same value to raw_input, you will get back the string '3'. In order to get the integer value of it, you can do int(raw_input('give me an integer: ')) In general I would suggest you use raw_input!

    • one year ago
  2. minimallinux
    Best Response
    You've already chosen the best response.
    Medals 0

    But, if you are using Python3.3 raw_input generates an error

    • one year ago
  3. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 1

    Yes cause it doesn't exist. It has been replaced by input() function!

    • one year ago
  4. minimallinux
    Best Response
    You've already chosen the best response.
    Medals 0

    OK Thanks

    • one year ago
  5. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 1

    No problem at all!

    • one year ago
  6. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 0

    @Chris2332 you siad that in general you would suggest raw_input over input...why? i mean input basically (as i understand )recognises whatever u type....why should i use a func that sees everything as a string unless i tell it to see it as smthing else?

    • one year ago
  7. minimallinux
    Best Response
    You've already chosen the best response.
    Medals 0

    I was thinking something along those lines, if 3.3 only has 'input' and it recognizes everything as is, then surely, as someone new to Python I should use that ?

    • one year ago
  8. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    In Python2.x raw_input works like input does in Python3.x. 2.x is a different thing altogether.

    • one year ago
  9. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 1

    @MicroBot I would suggest raw_input so you are always certain that the function always returns a string and then you manipulate it the way you want. So you cast it as you see fit or use it any way you might want. The control is yours effectively

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.