python raw_input function (48)

table of Contents

I. Introduction

Difference between the two .input and raw_input of

1. When the input is purely numeric

2. When the input character string to an expression

The principle function of three .input

 

 

I. Introduction

python 2.x versions have built-in functions raw_input and input two functions;

python 3.x version is not built-in functions raw_input, if you use the built-in functions raw_input in python 3.x version, you will be prompted: NameError: name 'raw_input' is not defined

 

Difference between the two .input and raw_input of

1. When the input is purely numeric

input returns numeric types, such as int, float

raw_inpout returns a string type, string type

 

2. When the input character string to an expression

input will be calculated numeric expression in the string, and raw_input does not.

The input "57 + 3": input will be an integer of 60; raw_input will be the string "3 + 57";

 

The principle function of three .input

Look python input document, you can see input by raw_input actually achieved, the principle is very simple, the following line of code:

def input(prompt):

    return (eval(raw_input(prompt)))

 

 

you may also like:

1.python built-in function input / eval

2.python list comprehensions

3.python dictionary derivations

4.python return logical operators

 

Reproduced please specify : ape say Python  »  Python raw_input function

 

                                                                         Technical exchanges, business cooperation please contact bloggers

                                                                                Scan code or search: ape say python

No public python tutorial

                                                                                           Ape say python

                                                                                  No. sweep the micro-channel public concern

Published 130 original articles · won praise 92 · views 30000 +

Guess you like

Origin blog.csdn.net/ZhaDeNianQu/article/details/104684052