Python uses raw_input to read the input value.

Source: Internet
Author: User

Python uses raw_input to read the input value.

This article describes the usage of raw_input in python in detail. Using raw_input can easily read data from the consortium console. The usage example is as follows:

1. input string

#13222319810101****nID = ''while 1:  nID = raw_input("Input your id plz")  if len(nID) != len("13222319810101****"):    print 'wring length of id,input again'  else:    break print 'your id is %s' % (nID)

2. Input an integer

nAge = int(raw_input("input your age plz:\n"))if nAge > 0 and nAge < 120:  print 'thanks!'else:  print 'bad age'print 'your age is %d\n' % nAge

3. Input floating point type

fWeight = 0.0fWeight = float(raw_input("input your weight\n"))print 'your weight is %f' % fWeight

4. Enter hexadecimal data

nHex = int(raw_input('input hex value(like 0x20):\n'),16)print 'nHex = %x,nOct = %d\n' %(nHex,nHex)

5. Input octal data

nOct = int(raw_input('input oct value(like 020):\n'),8)print 'nOct = %o,nDec = %d\n' % (nOct,nOct)

This example provides some learning reference for beginners of Python. If you are interested, you can debug and run this example to deepen your understanding of raw_input usage.


How does one obtain user input in Python?

You can use the input () function.
You can also use the raw_input () function.
Example:
>>> X = input ("x :")
X: 34
>>> Y = input ("y :")
Y: 42
>>> Print x * y
1428

How does python obtain keyboard input?

Content = input ("input :")
Or
Content = raw_input ("input :")

Because python versions are different, the supported input methods (input/raw_inpt) are different.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.