Home > other >  Python problem
Python problem

Time:12-29

Nasty, ask, one more question, please
Could you tell me why the second line of the input side to add double quotation marks, and the double quotation marks inside can't add content

CodePudding user response:

The eval () function is put inside a string parameter when expressions to perform,
Input the returned is a string, if the string is a "value", has been carried out the eval will get a value type, directly after the program is in need of a string type,
You can compare a below the difference of the final result:
> The eval (input (' please input temperature:))
Please input temperature: 12.6
12.6
> The eval (" input (' please input temperature: ') ")
Please input temperature: 12.6
'12.6'

On both sides of the input without parentheses, equivalent to 12.6 enter on the interpreter direct input;
On both sides of the input add parentheses, equivalent to the input in the interpreter '12.6' return,
Both get the final result,

CodePudding user response:

reference 1st floor DuskCrow_ response:
eval () function is put inside a string parameter when expressions to perform,
Input the returned is a string, if the string is a "value", has been carried out the eval will get a value type, directly after the program is in need of a string type,
You can compare a below the difference of the final result:
> The eval (input (' please input temperature:))
Please input temperature: 12.6
12.6
> The eval (" input (' please input temperature: ') ")
Please input temperature: 12.6
'12.6'

On both sides of the input without parentheses, equivalent to 12.6 enter on the interpreter direct input;
On both sides of the input add parentheses, equivalent to the input in the interpreter '12.6' return,
Get the final result is not the same, both

Understand understand, thank you
  • Related