首页 > 其他分享 >字符串练习

字符串练习

时间:2023-12-08 18:34:05浏览次数:36  
标签:saying never name 练习 print 字符串 message

字符串练习

练习2.3 个性化消息

name = 'eric'
text = 'would you like to learn some Python today?'
message = f"Hello {name.title()}, {text}"
print(message)

image

练习2.4 调整名字大小写

first_name = 'Key'
last_name = 'kilo'
full_name = f'{first_name} {last_name}'
print(full_name.title())
print(full_name.upper())
print(full_name.lower())

image

练习2.5 名言1

name = 'Albert Einstein'
saying = 'A person who never made a mistake never tried anything new.'
print(f'{name} once said, "{saying}"')

image

练习2.6 名言2

name = 'Albert Einstein'
saying = '"A person who never made a mistake never tried anything new."'
message = f'{name} once said, {saying}'
print(message)

或者

name = 'Albert Einstein'
saying = 'A person who never made a mistake never tried anything new.'
message = f'{name} once said, "{saying}"'
print(message)

练习2.7

name = '\n\tkilo\n '
print(name.lstrip())
print(name.rstrip())
print(name.strip())

image

练习2.8

filename = 'python_notes.txt'
simple_fname = filename.removesuffix('.txt')
print(simple_fname)

image

标签:saying,never,name,练习,print,字符串,message
From: https://www.cnblogs.com/Key-Kilo76/p/string-practice-z2fw6bg.html

相关文章

  • **第四章 字符串****part02**
    第四章字符串**part02**    28.找出字符串中第一个匹配项的下标 题目链接:https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/  暴力法Code:classSolution{public:  intstrStr(stringhaystack,stringneedle)......
  • mybatis动态sql将字符串转换成数字类型报错
    报错信息org.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.exceptions.PersistenceException: ###Errorqueryingdatabase.Cause:java.lang.NumberFormatException:Forinputstring:"xxx" ###Cause:java.lang.NumberFo......
  • 基于vue脚手架的练习2
    <template><div><span>父值为:</span>{{to_value}}<button@click="clear()">清空</button></div></template><script>exportdefault{props:['to_value'],methods......
  • 这就解释了tuple("单个多字符字符串") type==tuple, 其实是字符串被拆分到元组中, 以
    #单个多字符字符串拆分list("单个多字符字符串")tuple("单个多字符字符串")set("单个多字符字符串")#重新排序#dict不行ValueError:dictionaryupdatesequenceelement#0haslength1;2isrequiredlist("单个多字符字符串",)tuple("单个多字符字符串",)set("......
  • 20231208练习
    【2022.12.30提高组模拟】依依寺(yiyi)ProblemDescription从前有个寺庙,名为依依寺。寺庙因《诗经.小雅》中的“昔我往矣,杨柳依依。今我来思,雨雪霏霏。“而得名。庙里有个老和尚和小和尚。老和尚叫章丘样,小和尚叫章扬扬。老和尚说“从前有个寺庙,名为依依寺。庙里有个老和尚和小......
  • java JSON对象与字符串间的转换
    importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONObject;//字符串转为JSON对象StringstrParam="{\"callerid\":\"013941128270\",\"timestart\":\"2021-07-2709:37:42\",\"status\"......
  • day8、9字符串代码随想录
    第四章字符串●344.反转字符串●541.反转字符串II●卡码网:54.替换数字●151.翻转字符串里的单词●卡码网:55.右旋转字符串1反转字符串编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组char[]的形式给出。不要给另外的数组分配额外的空间,你必须......
  • 优雅提效:Guava的字符串处理工具
    第1章:引言大家好,我是小黑,今天咱们要聊一聊GoogleGuava这个超棒的Java库,尤其是它的字符串处理工具。对于Java程序员来说,字符串处理是日常工作的一部分,而Guava在这方面提供了非常强大的支持。使用Guava处理字符串不仅可以提高效率,而且代码会更简洁、更优雅。Guava库由Google开发......
  • Java File类详解(下)练习部分
    练习第一题需求:在当前模块下的aaa文件夹中创建一个a.txt文件importjava.io.File;importjava.io.IOException;publicclassFileExer01{publicstaticvoidmain(String[]args)throwsIOException{Filef1=newFile("AllInOne\\aaa");f1.mkdirs();Filesrc=ne......
  • 天池AI练习生计划 - 第二期AI数学基础入门与实践,火热进行中!通关赢取双重礼品!
    机器视觉学术研究与产品研发专家雷明,带领您详细学习人工智能领域需要用到的数据知识点,从学习者蜕变为AI新星!轻松来闯关,即可领取双重礼品~实训培训证书:通关两个关卡即可领取阿里云定制长袖T恤:通关全部关卡即可领取活动地址:https://tianchi.aliyun.com/specials/promotion/math......