Special symbols
Some symbols have special definitions in Python compared with C/C ++ and Java.
_: Value of the last expression
Example:
>>> 4/2 <br/> 2 <br/> >>>_< br/> 2 <br/> Print _ + 10 <br/> 12
%: String format Operator
Example:
>>> Print '% s is Number % d! '% ('Python', 1) <br/> python is number 1!
>>: Output redirection
Example:
>>> Logfile = open ('/tmp/mylog.txt', 'A') <br/> Print> logfile, 'fatal error: Invalid input! '<Br/> logfile. Close ()
#: Comments from # To the end of the line.
//: For Python 3 +, '/' indicates the real division, '//' indicates the floor Division (for 2. for Version X, you need to import _ future _ division)
# Python version 2.5 <br/> 5/2 <br/> 2 <br/> 5 // 2 <br/> 2 <br/> from _ future _ import Division <br/> 5/2 <br/> 2.5 <br/> 5 // 2 <br/> 2
+, *: For strings, '+' indicates string connection, and '*' indicates string duplication.
Example:
>>> 'Hello' + 'World! '<Br/>' Hello world! '<Br/>>>> 'hello' * 2 <br/> 'hellohello'
[Begin: end]: The operation symbol of the slice. value range: [begin, end). If you do not enter begin, it indicates all elements before the end (excluding the end itself). If you do not enter end, it indicates the begin and all its elements. The index starts from 0. In particular, the last index can be represented by-1.
Example:
>>> Val = [1, 2, 3, 4] <br/> Val [0] <br/> 1 <br/> Val [-1] <br/> 4 <br/>> Val [0: -1] <br/> [1, 2, 3] <br/> Val [0:] <br/> [1, 2, 3, 4] <br/> Val [:-1] <br/> [1, 2, 3] <br/> Val [:] <br/> [1, 2, 3, 4]
''': Three consecutive quotation marks, which are used as the start and end of a string. A string can span multiple rows and contain special symbols such as line breaks and tabs. When an HTML or SQL statement is required, using ''' makes the code more concise and clear.
Cursor.exe cute (''' <br/> insert into warning_type <br/> (type_id, type_name, urgency, description) <br/> values (0, 'test info ', 0, 'test info'); <br/> ''')
U: the string is preceded by the U symbol, indicating that the string is a unicode string.
>>> S = 'hello' <br/> type (s) <br/> <type 'str'> <br/> S = u'hello' <br/> type (s) <br/> <type 'unicode '>