Variable:
1. You must assign a value before using the variable;
2. Variable names can be letters, numbers, underscores, but cannot start with numbers;
3. The letters can be uppercase and lowercase, but the case is different, such as Fishc and Fishc are not the same;
4. The equal sign (=) is the meaning of the assignment, the left is the name behind the value can not be written backwards;
5. Variable name as far as possible to professional. Readability is stronger.
Escape characters:
1. If we want to print let ' s go!
>>>let ' s go!
This will be an error.
Use the following method (use the backslash!) )
>>>let\ ' s go!
You can get "let's go!"
or use double quotes:
>>>print ("Let ' s go!")
Let ' s go!
Original string:
But if you want to print "C:\now"
Method One:
>>>str = ' C:\\now '
>>>print (str)
C:\now
But if you want to print "C:\now\haha\miaomiao\bigeng"
Method:
>>>str = R ' C:\now\haha\miaomiao\bigeng '
>>>print (str)
C:\now\haha\miaomiao\bigeng
But there is one problem: if you want to print "C:\now\haha\miaomiao\bigeng\"
The method above will be error-solving:
>>>str = R ' C:\now\haha\miaomiao\bigeng ' + ' \ \ '
>>>print (str)
C:\now\haha\miaomiao\bigeng\
Long string
If you want to print:
If I love you--
never learn the birds,
to repeat the monotonous song of the shade,
also not only like the fountain,
perennial send to cool comfort;
also more than Xianfeng, increase your altitude, Foil Your Majesty.
even daylight.
even spring rain. The
workaround is as follows:
>>>str = "" "
If I love you--
Never learn the birds of infatuation,
also more than just a fountain,
All year round to bring cool comfort;
even daylight.
even spring rain.
to get the expected results.
< strong> Single Double quote:
>>>s6 = ' I realy like "python" !‘
>>>print (S6)
I realy like "python"!
Again:
>>>S5 = "Let ' s go!"
>>>print (S5)
Let ' s go!
Python Strings and variables