Python learning: Input and output

Source: Internet
Author: User

One: Output

With Print plus a string, you can output the specified text on the screen. For example, enter ' Liu Yan Liang '

print ' Liuyanliang '


printStatements can also be followed by multiple strings, separated by a comma "," to be connected to a string of outputs:

print ' Liu ', ' Yan ', ' Liang '


printEach string will be printed sequentially, and a comma "," will output a space, so the output string is spelled together.


Two: input

Now you can already use print output the results you want. But what if you want users to enter some characters from the computer? Python offers a raw_input , which allows the user to enter a string and store it in a variable. For example, enter the user's name:

>>> name = raw_input()Michael

When you type name = raw_input() and press ENTER, the python interactive command line is waiting for your input. At this point, you can enter any character and then press ENTER to complete the input.

After the input is complete, there is no hint, and the Python interactive command line goes back to >>> status. So where is the content we just entered? The answer is to deposit to name variable. can be directly input name view variable contents:

>>> name‘Michael‘

raw_inputand the print is the most basic input and output below the command line!


Python learning: input/output

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.