Input and output of Python (Learning note i)
With Print plus a string, you can output the specified text to the screen. As the following command:
print ' hello,world! '
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/92/9A/wKioL1kBUMOBbl9hAAAUx1cMPj0582.png "title=" 22. PNG "alt=" Wkiol1kbumobbl9haaaux1cmpj0582.png "/>
The print statement can also be followed by multiple strings, separated by a comma "," that can be connected to a string of outputs:
print ' My name is WTF, ', ' I am learning Python. '
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/92/9B/wKiom1kBUfHAzitXAAAJTZanaqc629.png "title=" 22. PNG "alt=" Wkiom1kbufhazitxaaajtzanaqc629.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/92/9B/wKiom1kBUs3xv4zvAACNa7AcicQ430.png "title=" 22. PNG "alt=" Wkiom1kbus3xv4zvaacna7acicq430.png "/>
It can be used directly as a calculator in Python, for example:
(1) Basic subtraction Surplus
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/92/9B/wKiom1kBU-GiG5PUAAAJJPQ31io965.png "title=" 22. PNG "alt=" Wkiom1kbu-gig5puaaajjpq31io965.png "/>
(2) difference between integer division and exact division:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/92/9B/wKioL1kBVOiBJwW7AAAIBbK1a9A507.png "title=" 22. PNG "alt=" Wkiol1kbvoibjww7aaaibbk1a9a507.png "/>
Note: Because integer division takes only the integer part of the result, to do the exact division, you just need to replace one of the integers with a floating-point number to do the division. As shown in the situation.
(3) Representation of decimals
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/92/9C/wKiom1kBVkOg7pErAAAHXL_9i70371.png "title=" 22. PNG "alt=" Wkiom1kbvkog7peraaahxl_9i70371.png "/>
Note: where E represents the number 10 here!
You can now print out the results you want. But what if the computer wants the user to enter some characters? Python provides a
A raw_input that allows the user to enter a string and store it in a variable. For example, enter the user's name:
Command: Name = Raw_input ()
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/92/9C/wKioL1kBWvOhvLEzAAALXPI1Wec162.png "title=" 22. PNG "alt=" Wkiol1kbwvohvlezaaalxpi1wec162.png "/>
Note:
When you enter name = Raw_input (), a flashing cursor appears below, enter what you want, and click enter!
When print, name does not enclose the quotation marks!
You can enter name directly and print out what you define!
In a computer program, a variable can be not only an integer or a floating-point number, but also a string, so name as a variable is a string.
Command: Name = Raw_input ()
wtf
print ' Hello, ', name
:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/92/9C/wKioL1kBXDqyE4TPAAAHpNdqM24903.png "title=" 22. PNG "alt=" Wkiol1kbxdqye4tpaaahpndqm24903.png "/>
Now that we know the basic usage of raw_input (), but the input command name = Raw_input () without any reminders, it is very "abrupt", here is a way to avoid such embarrassment.
Command: Name = raw_input (' Please enter your name: ')
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/92/9E/wKiom1kBXgeirRIFAAAKeoYWHDI121.png "title=" 22. PNG "alt=" Wkiom1kbxgeirrifaaakeoywhdi121.png "/>
Note:
1. Inputs are input and outputs are output, so we refer to the input and output collectively as input/output, or abbreviated to IO.
2.raw_input and print are the most basic inputs and outputs at the command line, but the user can also complete the input and output through other more advanced graphical interfaces, such as entering their name in a text box on a webpage and clicking "OK" to see the output on the page.
This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1919937
Input and output of Python (Learning note i)