Life is short, I use Python to study notes--the fourth day __python

Source: Internet
Author: User
Tags hmac string format in python

1 formatted output
Format character conversion
%c to character (ASCII value, or string of length)
%ra precedence repr () function for string conversions
%s precedence for string conversions with the str () function
%d/% I convert to signed decimal number
%ub to unsigned decimal number
%ob to unsigned octal number
%xb/%xb (Unsigned) to unsigned hexadecimal numbers (x/x represents the large
lowercase of converted hexadecimal characters)
%e/%e to Branch Learning counting method (e/e control output e/e)
%f/%f to floating-point number (fractional natural truncation)
%g/%g%e and%f/%e and%f's shorthand
%% output%
Format operator Auxiliary Instruction
Symbolic action
* define width or decimal Dot Precision
-used for left alignment
+ show plus sign (+)
<sp> Show blanks before positive numbers
# in the octal number before 0 (' 0 '), display ' 0x ' or ' 0X ' in front of hexadecimal (depending on whether the
is ' x ' or ' X ')
0 displays the number preceded by the ' 0 ' instead of the default space
% '% ' output a single '% '
(VAR) mapping variable (dictionary parameter)
M.N m is the minimum total width shown, n is the number of digits after the decimal point (if available)
For example
>>> "%x"% 108
' 6c '
>>>
>>>%x% 108
' 6C '
>>>
>>> % #X% 108
' 0x6c '

Original string operator (R/R)
This ' r ' can be lowercase or uppercase, the only requirement is that it must be immediately preceding the first quotation mark.
In the first example of three examples, we need a backslash plus a ' n ' instead of a newline character.:
> >> ' \ n '
\ n '
>>> print ' \ n '
>>> R ' \ n '
' \\n '
>>> print R ' \ n '
\

Escape character at the beginning of a backslash
/x octal decimal hexadecimal character Description
0 0x00 NUL null character NUL
\a 007 7 0x07 BEL ring character
\b 010 8 0x0 8 BS backspace
\ t 011 9 0x09 HT horizontal tab
\ 012 0x0A LF linefeed
\v 013 0x0b VT Vertical tab
\f 014 0x0C FF page Change
\ r 01 5 0x0D CR return
\e 033 0x1b ESC escape
\ 042 0x22 "double quotes
\ 047 0x27 ' single quotes
\ 134 0x5c \ Backslash
Three Quotation marks
Although you can use single or double quotes to define a string, single or double quotes are less convenient if you need to include special characters such as line breaks. Python's triple quotes are meant to solve this problem,
it allows a string to span multiple lines, and a string can contain line breaks, tabs, and other special characters
>>> a= ' A\NBC '
>>> Print a
 a
BC
>>>
...
String invariance >>> ' abc ' + ' def '
' abcdef '
Assign values to variables is nothing different:
>>> s = ' abc '
>>> s = s + ' d EF '
>>> s
' abcdef '
in the example above, it seems that we first assigned "ABC" to s, and then added "Def" at the end of S. This looks like
the string seems to be variable, in fact it is in "S+ ' Def" "When this operation was done, a new string was created,
and then the new object was assigned to S, and the original string ' abc ' was refactored out


Unicode
Modules related to string types
Module description
string strings manipulate related functions and tools, such as the template class.
Re Regular expression: powerful string pattern matching module
Conversion between struct string and binary
C/stringio the string buffer object, which is similar to the file object.
Base64 Base 16,32,64 Data codec
Codecs decoder registration and base class
Crypt for unilateral encryption
Diffliba find the difference between the sequences
Hashlibb a variety of different security hashing algorithms and Information Digest algorithm APIs
Python implementation of information authentication algorithm for HMAC HMAC
MD5D RSA's MD5 Information Digest authentication
Rotor provides multi-platform encryption and decryption services
Secure hashing algorithm for Shad Niat sha
Stringprepe provides a Unicode string for the IP protocol
Textwrape Text Packaging and padding
Unicodedata Unicode Database

Summary of string key points

The most common two quotes in Python are single quotes (') and double quotes ("). The actual contents of the string
are the characters between these single quotes (') or double quotes ("), excluding the quotation marks themselves.
It is useful to create a string with two quotes, because when you include single quotes in your string, if
creates a string in single quotes, the double quotes in the string do not need to be escaped. And vice versa
the string format operator (%) provides functionality similar to printf ().
The string format operator (see 6.4.1) provides a spirit
Live mode that creates custom strings based on a variety of input types. It also provides similar to C + + The interface of the format operation in the world.
Triple quotes
are in section 6.7.2, we introduced three quotes, which can contain special characters such as a newline carriage return or a TAB key
in a three-quote string. A three-quote string is defined by each of the three single quotes (' ") on either side or three double quotes (" ") on either side. .
The original string uses its intent for each special string
in 6th. 4.2, we describe the original string and discuss the special
sex that they do not escape by using backslashes. This feature makes the original string very useful for those situations that require the literal character of the string. For example, when you define a regular expression
.
The Python string is not ended by NUL or ' yes '. One of the major problems with
C programming is that you access a space that is not yours after a string, which occurs when you
do not add non-terminal, NUL, or ' ' to the end of the string (ASCII value is 0) . Python not only automatically manages internal
storage, but also removes the burden of C or a small problem. The strings in Python do not end with NUL, so
you do not need to worry about whether you have added non-terminal. The string contains only what you define, nothing else.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.