Python Basics - Input and Output

In any language, the input and output codes are the most basic start,

so, the first chat to the input and output

Export

In python, we generally use print ()  output, enter the information you want to export in brackets, wrapped in quotation marks (single or double three can be), for example, we output a 'hello, python'

>>>print('hello,python')

>>>hello,python

>>>print("hello,python")

>>>hello,python

If you want to output a plurality of strings, this can be done: by comma separated, then the middle of each string is separated by spaces,

>>>print('hello', 'world', 'python')

>>>hello world python

Can do so with a plus sign , then there is no connection between each string connector, put together directly

>>>print('hello' + 'world' + 'python')

>>>helloworldpython

print can also be used to output digital - digital output when the parcel without quotes

>>>print(20)

>>>20

Also it is used to calculate an arithmetic operation between the digital

>>>print(20 + 20)

>>>40

About print There are two common built-in method

end will output the contents of the final with a specified character, in fact, if the value of end is not specified, the default is a newline character is \ n. So print twice, it is displayed as two lines, rather than in a row

>>>print('hello', end='#')

>>>hello#

sep at a specified character to connect print content

>>>print('hello', 'world', 'python', sep='@')

>>>hello@world@python

Entry

Chat finished output, the input to talk about the following
in python, to prompt the user with the input content

>>> input ( 'Please enter your name:')

>>> Please enter your name:

After pressing Enter your name Enter is enter OK

>>> Please enter your name: Pharaoh next door

>>> 'next door Pharaoh'

Generally, we will be assigned to a user input variables (variables as to what the future will say, here as a symbol, such as our tube computer called 'computer', just a name on behalf of an entity), like this

>>> name = input ( 'Please enter your name:')

>>> Please enter your name: Pharaoh next door

When we need to use the 'next Pharaoh' names this time, direct input on the screen name , press Enter, Pharaoh will appear on your screen, PS: the best little call Pharaoh ...

>>>name

>>> 'next door Pharaoh'

END

Remember: All signs are in English format, do not enter in python into Chinese symbols, otherwise it will error of.
Enter to tell the program what it needs content
output is the result of the implementation of its program to tell the user
therefore, everything is built on the input and output, we must grasp Ay ~ ~

[Distributed learning python reptile - from foundation to combat]

Guess you like

Origin blog.51cto.com/12486145/2453546