Python3. X Resume (7)-----People alive is the process of inhaling and exhaling.

Source: Internet
Author: User

As long as it is alive, give yourself a reason for breathing, as long as there is this reason, forcing themselves to go, will have better results.

------------Hashlinux

Input and output outputs

by print() Adding a string to the parentheses, you can output the specified text to the screen. For example ‘hello, world‘ , the output is implemented in code as follows:

>>> print (' Hello, World ')

print()A function can also accept multiple strings, separated by a comma "," and can be connected to a string of outputs:

>>> print (' The quick brown fox ', ' Jumps over ', ' the Lazy Dog ') The "quick brown fox jumps over the" the Lazy Dog

print()Each string will be printed sequentially, and a comma "," will output a space, so the output string is spelled like this:

650) this.width=650; "Src=" http://www.liaoxuefeng.com/files/attachments/ 001431643506965540b8016b45c4d27b84c734543f78840000/l "alt=" Print-explain "/>

print()You can also print an integer, or calculate the result:

>>> print (300>>>) print (100 + 200) 300

Therefore, we can 100 + 200 print the results of the calculation a little more beautiful:

>>> print (' 100 + 200 = ', 100 + 200) 100 + 200 = 300

Note that for 100 + 200 the Python interpreter to automatically calculate the result 300 , however, ‘100 + 200 =‘ it is a string rather than a mathematical formula, and Python treats it as a string, explaining the printing results yourself.

Input

Now, you can already print() output the results you want. But what if you want users to enter some characters from the computer? Python provides one that allows the input() user to enter a string and store it in a variable. For example, enter the user's name:

>>> name = input () Michael

When you type name = 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.

Once the input is complete, there is no hint, and the Python interactive command line is back in >>> state. So where is the content we just entered? The answer is stored name in the variable. You can enter the contents of a name view variable directly:

>>> name ' Michael '

What is a variable? please recall the basic knowledge of algebra in junior high School Mathematics:

The square is side length a , then the square area is a x a . Consider the side length as a a variable, and we can a calculate the square's area according to the value, for example:

If a=2, the area is a x a = 2 x 2 = 4;

If a=3.5, the area is a x a = 3.5 x 3.5 = 12.25.

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.

To print out the name contents of a variable, you can also use a function, in addition to writing directly name and then pressing ENTER print() :

>>> print (name) Michael

With the input and output, we can change the last printed ‘hello, world‘ program to a somewhat meaningful program:

name = input () print (' Hello, ', name)

Run the above program, the first line of code will let the user enter any character as their own name, and then into the variable, the name second line of code according to the user's name to the user hello , such as input Michael :

c:\workspace> python Hello.pymichaelhello, Michael

However, when the program runs, there is no prompt to tell the user: "Hey, just enter your name", this looks very unfriendly. Fortunately, it allows input() you to display a string to prompt the user, so we change the code to:

Name = input (' Please enter your name: ') print (' Hello, ', name)

Run this program again, you will find that the program runs, will first print out please enter your name: , so that the user can follow the prompts, enter the name after the hello, xxx output:

c:\workspace> python hello.pyplease Enter your Name:michaelhello, Michael

Each time you run the program, the output will be different depending on the user input.

At the command line, the input and output are so simple.

Summary

Any computer program is to perform a specific task, with the input, the user can tell the computer program required information, with the output, the program can be run to tell the user the results of the task.

Inputs are input and outputs are output, so we refer to the input and output collectively as input/output, or abbreviated to IO.

input()And print() is the most basic input and output below the command line, however, the user can also complete the input and output through other more advanced GUI, for example, enter their name in a text box on the webpage, click "OK" to see the output information on the webpage.

Practice

Please use the print() output 1024 * 768 = xxx :










#!/usr/bin/env Python3

#-*-Coding:utf-8-*-

Name = input()

Print ('Hello,', name)


This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1792716

Python3. X Resume (7)-----People alive is the process of inhaling and exhaling.

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.