Python Strings用法

0.在线参考资料:

1.
     chr()
chr(i)

Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range.

根据ascii码返回某个字符,注意函数参数需要写为 0x XX



     ord()
ord(c)

Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example, ord('a') returns the integer 97 and ord('\u2020') returns 8224. This is the inverse of chr().

               返回某个字符对应的ascii码的十进制表示

2、capitalize
     str.capitalize()

Return a copy of the string with its first character capitalized and the rest lowercased.

3、
     str.isupper()

Return true if all cased characters [4] in the string are uppercase and there is at least one cased character, false otherwise.

str.lower()

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


The lowercasing algorithm used is described in section 3.13 of the Unicode Standard.
4、
str.join(iterable)

Return a string which is the concatenation of the strings in the iterable iterable. A TypeError will be raised if there are any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method.
5、
str.lower()

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


For 8-bit strings, this method is locale-dependent.
6、
string.lower(s)

Return a copy of s, but with upper case letters converted to lower case.







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
stripped_strings是BeautifulSoup库中的一个方法,用于获取HTML文本中的所有非空白字符串。它可以帮助我们快速提取出HTML中的文本内容,并自动去除空白字符。 在使用stripped_strings方法时,首先需要导入requests和BeautifulSoup库,然后通过requests库发送get请求获取网页的HTML源代码。接着使用BeautifulSoup库对HTML源代码进行解析,创建一个BeautifulSoup对象。然后通过选择器定位到目标元素,并使用stripped_strings方法来获取其中的文本内容。最后将获取到的文本内容存储到一个列表中,以便后续处理或展示。 如果需要获取HTML中的多个内容,可以使用遍历的方式,如for循环遍历soup.strings,然后使用repr(string)来打印每个非空白字符串。这样可以将去除空白字符后的文本逐个输出。 总结来说,stripped_strings方法是用于提取HTML文本中的非空白字符串的方法,可以帮助我们快速获取并处理HTML中的文本内容。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Python爬虫之string、strings、stripped_strings、get_text和text用法区别](https://blog.csdn.net/qq_22592457/article/details/100597190)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Python编程-- BS4解析](https://blog.csdn.net/weixin_41905135/article/details/126220373)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值