String.casefold and String.Lower differences in Python

Source: Internet
Author: User

string.casefold和 string.lower DifferencePython 3.3 introduces a string.casefold method whose effect is very similar to that of turning a string.lower string into lowercase, so what's the difference between them? Their respective application scenarios? when Unicode is used casefold string.casefold Official Note:

Casefolding is similar to lowercasing and more aggressive because it's intended to remove all case distinctions in a stri Ng. For example, the German lowercase are ‘ß‘ equivalent to "ss" . Since It is already lowercase, lower() would does nothing to ‘ß‘ ; casefold() Converts it to "ss" .

The casefolding algorithm is described in sections 3.13 of the Unicode standard

lower()‘A-Z‘It is only valid for ASCII, but in some other languages there is no way to get a lowercase case. The example in the document is the lowercase in German ‘ß‘ ‘ss‘ :

s = ‘ß‘s.lower() #  ‘ß‘s.casefold() # ‘ss‘
string.lower Official Note:

Return a copy of the string with all the cased characters [4] converted to lowercase.

The lowercasing algorithm used is described in sections 3.13 of the Unicode standard

Reference

Https://docs.python.org/3/library/stdtypes.html#str.casefold

https://segmentfault.com/q/1010000004586740/a-1020000004586838

Summary

Chinese & English Environment under, continue to use lower() no problem; To work with other languages and when case is presentcasefold()

String.casefold and String.Lower differences in Python

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.