1. Input
Python input mainly has input and raw_input two functions, what is the difference between these two?
Run the code, please.
Name=input (' Please input somthing: ') print ' What are input is: ' +name
PS: Everyone familiar with C + + knows that when we define a variable we need to define its variable type before the variable, and here we define a name variable, but we don't specify its type, which is also a feature of Pythond, Python implements dynamic deterministic type, The type is determined based on the assignment of the variable, which is somewhat similar to the Var type in C #, and of course the type entered here is, of course, a string
Run the following code
Name=raw_input (' Please input somthing: ') print ' What are input is: ' +name
We will find the difference between the two, because input assumes that the user is entering a valid Python expression, and if we enter hello in knowledge, it will prompt an error, but if we enter it as a string, the program will run perfectly (' Hello ')
But it's hard to remember the input string every time, so raw_input solves the problem, and Raw_input takes all the input as raw data and puts it into the string (name).
So if there are no special requirements for input, we should use raw_input as much as possible.
Either input or raw_input the string inside the parentheses is displayed as a hint, and of course it can be empty, so that no hint message is displayed
2. Output
The Python output uses print, as if the print has been encapsulated as a function after Python3, and I'm using 2.7 so I can continue to output using code similar to the following
print ' Hello python '
PS: People familiar with C + + know that in C + + they use double quotes to represent strings, and what are double quotes in python for?
The answer is that in Python, the function of single and double quotes is the same, representing a string.
But when we need to have single or double quotes in the string, the combination of single and double quotes is also very convenient in addition to using the escape character (\).
Run the following code
Print "Let ' s go!" print ' I said: "You're best!"
In addition, the use of three single quotes in Python is also reasonable, what will achieve what function?
Run the code, please.
print ' hell0, my name is er_plough,nice to meet you! '
So when our output is going to need a newline, that's what he does!
Of course, it's also possible.
print ' hell0, \nmy name is er_plough,\nnice to meet you! '
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Python note 1] input and output