字符串的函数应用

Emma Woodhouse, handsome, clever, and rich, with a comfortable home and happy disposition, seemed to unite some of the best blessings of existence; and had lived nearly twenty-one years in the world with very little to distress or vex her.

针对上述语料,请完成以下操作:

(1) 统计上述文本中共有多少个单词:

a = "Emma Woodhouse, handsome, clever, and rich, with a comfortable home and happy disposition, seemed to unite some of the best blessings of existence; and had lived nearly twenty-one years in the world with very little to distress or vex her."
b = a.replace(',','')
c = b.replace('.','')  #替掉(或者说是删除掉)逗号和句号,为下一步进入列表的规范化做准备(其实是为了第二问做准备)
d = c.split(' ')  #空格分隔单词输入列表
print(len(d))  #输出列表元素数量

(2) 输出上述文本中所有长度为4个字母的单词:

list_i = []  #先预设一个空列表
for i in d:
    if len(i) == 4:
        list_i.append(i)  #经典的列表遍历,查找长度并将查找结果输入新列表
print(list_i)

(3) 将上一步输出的单词分别以首字母大写、全大写、全小写的方式输出:

for word in list_i:
    print(word.title(),word.upper(),word.lower())  #毋庸多言

这样上传一下云端,顺便分享一波,还望指教。 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在Hive中,有许多字符串函数可用于处理和操作字符串。其中一些常用的字符串函数包括: 1. 字符串长度函数:length(str) 这个函数返回字符串str的长度。 2. 字符串反转函数:reverse(str) 这个函数返回将字符串str反转后的结果。 3. 字符串连接函数:concat(str1, str2, ...) 这个函数将多个字符串连接在一起。 4. 带分隔符字符串连接函数:concat_ws(sep, str1, str2, ...) 这个函数将多个字符串连接在一起,并使用指定的分隔符sep进行分隔。 5. 字符串截取函数:substr(str, start, len) 或 substring(str, start, len) 这个函数返回从字符串str中从start位置开始,长度为len的子字符串。 6. 字符串转大写函数:upper(str) 或 ucase(str) 这个函数字符串str转换为大写格式。 7. 字符串转小写函数:lower(str) 或 lcase(str) 这个函数字符串str转换为小写格式。 8. 去空格函数:trim(str) 这个函数去除字符串str两端的空格。 9. 左边去空格函数:ltrim(str) 这个函数去除字符串str左边的空格。 10. 右边去空格函数:rtrim(str) 这个函数去除字符串str右边的空格。 这些是Hive中一些常用的字符串函数,你可以根据需要选择使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Hive--函数--常用内置函数--字符串函数](https://blog.csdn.net/qq_46893497/article/details/110948038)[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%"] - *2* *3* [Hive常用字符串函数](https://blog.csdn.net/weixin_43823423/article/details/86663824)[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
发出的红包

打赏作者

山河之书Liu_Zixin

不要打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值