We chose to do Python programming under Ubuntu: Create a. py file, which starts with the Python code, and then uses the command $python file name in the shell to display the results of the run.
Here are a couple of string-related functions and syntax:
1. Input
Name = input ("What ' s your name?") Print "Hello," + name + "!"
Input will be in the output "What ' s your name?" Let the user enter, if at this time the user input Tom, will be an error--"Nameerror:name ' Tom is not defined", but the input "Tom" will print "Hello, tom!". This is because input requires the user to enter their name with quotation marks. Obviously this is a bit harsh, so let's look at the following function.
2. Raw_input
Age = Raw_input ("What old is You?")
Entering 21 is correct at this point because Raw_input will take all of the input as raw data and put it into a string.
In general, we use the Raw_input function whenever possible.
3. Escape character ' \ '
Print "Hello, world!"
Will print Hello, world! Also, we can use it on an expression:
1 + 2 + 4 + 5
Results are printed in 12.
4. repr
This function preserves the original form of the input, and for an example, it's clear.
If you use print only, it will replace the quotation marks of the string and the long integer L,REPR will retain these characteristics.
Python's Path (ii) string