• 列表、元组、字符串方法,字符串的编码


    列表的方法

    查:index、count和元组方法一样

    元组的方法

    字符串的方法

    isdigit判断是否为纯数字

     

    isalpha判断是否为纯字母

    endswitch判断字符串是以什么结尾,相反startswitch是以什么开头

    islower判断字符串是否以小写字母开头,相反isupper是否以大写字母开头

    upper字符串全部改为大写,相反lower字符串全部改为小写

    strip()删除空格,lstrip()删除起始位的空格,rstrip()删除结束位的空格。

    capitalize()让第一个字母大写

    title()让每个英文单词的首字母大写,英文单词空格或者逗号隔开。

     

    字符串的编码

    字符串在Python内部的表示是unicode编码,因此在做编码转换时候,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。

    decode的作用是将其他编码的字符串转换成unicode编码

    encode的作用是将unicode编码转换成其他编码的字符串

    utf-8和gbk的编码格式不一样

     

  • 相关阅读:
    LeetCode "Median of Two Sorted Arrays"
    LeetCode "Distinct Subsequences"
    LeetCode "Permutation Sequence"

    LeetCode "Linked List Cycle II"
    LeetCode "Best Time to Buy and Sell Stock III"
    LeetCode "4Sum"
    LeetCode "3Sum closest"
    LeetCode "3Sum"
    LeetCode "Container With Most Water"
  • 原文地址:https://www.cnblogs.com/shijin7/p/9047844.html
Copyright © 2020-2023  润新知