当前位置: 首页 > news >正文

织梦软件怎么使用域名做网站网站更换服务器 seo

织梦软件怎么使用域名做网站,网站更换服务器 seo,软件开发和网页设计哪个好,物流建设网站总结报告文章目录 专栏导读1、拼接字符串2、获取字符串长度3、字符串切片4、字符串替换:5、字符串分割6、字符串查找7、字符串大小写转换8、字符串去除空白9、字符串格式化:10、字符串编码与解码:11、字符串判断12、字符串填充与对齐总结 专栏导读 &a…

文章目录

  • 专栏导读
  • 1、拼接字符串
  • 2、获取字符串长度
  • 3、字符串切片
  • 4、字符串替换:
  • 5、字符串分割
  • 6、字符串查找
  • 7、字符串大小写转换
  • 8、字符串去除空白
  • 9、字符串格式化:
  • 10、字符串编码与解码:
  • 11、字符串判断
  • 12、字符串填充与对齐
  • 总结

专栏导读

🔥🔥本文已收录于《30天学习Python从入门到精通》

🉑🉑本专栏专门针对于零基础和需要重新复习巩固的同学所准备的一套基础班教学,从0基础到精通Python,轻松掌握Python,欢迎各位同学订阅,专栏订阅地址:点我直达

🤞🤞此外如果您已工作,如需利用Python解决办公中常见的问题,欢迎订阅《Python办公自动化》专栏,订阅地址:点我直达

1、拼接字符串

  • ①:使用加号+

  • ②:使用join()方法

s1 = "Hello"  
s2 = "World"  
s3 = s1 + " " + s2  # "Hello World"  
s4 = " ".join([s1, s2])  # "Hello World"
print(s3)
print(s4)

2、获取字符串长度

  • 使用len()函数

s = "Hello"  
length = len(s)  # 5
print(length)

3、字符串切片

  • 使用[start:stop:step]语法

  • [首:尾:步长],以前当老师的时候,这里我总是教:取头不取尾,要是想取到尾,尾+1

s = "HelloWorld"  
substring = s[0:5]  # "Hello"  
substring_with_step = s[0:10:2]  # "HloW"
print(substring)
print(substring_with_step)

4、字符串替换:

  • 使用replace()方法

s = "Hello World"  
new_s = s.replace("World", "Python")  # "Hello Python"
print(new_s)

5、字符串分割

  • 使用split()方法

s = "Hello,World,Python"  
words = s.split(",")  # ["Hello", "World", "Python"]
print(words)

6、字符串查找

  • 使用find(), index(), count()等方法

s = "Hello World"
index = s.find("World")# 返回开始的第一个索引
count = s.count("o") # 返回出现的次数
print(index, count)

7、字符串大小写转换

  • 使用upper(), lower(), capitalize(), title()等方法

s = "hello world"
s_upper = s.upper() # 全部字母大写
print(s_upper)s2 = "HELLO WORLD"
s_lower = s2.lower()  # 全部字母大写
print(s_lower)s_capitalize = s.capitalize()# 首字母大写
print(s_capitalize)s_title = s.title()# 每个单词首字母大写
print(s_title)

8、字符串去除空白

  • 使用strip(), lstrip(), rstrip()等方法

# 字符串去除空白
# 使用strip(),去除所有空格
# lstrip(),去除左边空格
# rstrip(),去除右边空格
str = "   hello world   "
print(str.strip())
print(str.lstrip())
print(str.rstrip())

9、字符串格式化:

  • 使用str.format()方法

  • 使用f-string(Python 3.6+)

name = "Alice"
age = 30
formatted_string = "My name is {} and I am {} years old.".format(name, age)
formatted_fstring = f"My name is {name} and I am {age} years old."
print(formatted_string)
print(formatted_fstring)

10、字符串编码与解码:

  • 使用encode()和decode()方法

s = "Hello"  
encoded = s.encode("utf-8")  # bytes 对象  
decoded = encoded.decode("utf-8")  # "Hello"
print(encoded)
print(decoded)

11、字符串判断

  • 使用startswith(), endswith(), isalpha(), isdigit(), isalnum(), isspace()等方法

s = "Hello123"
is_start_with_hello = s.startswith("Hello")  # 判断字符串是否以Hello开头
is_digit = s.isdigit()  # 判断字符串是否全为数字
is_alpha = s.isalpha()  # 判断字符串是否全为字母
is_alnum = s.isalnum()  # 判断字符串是否全为字母和数字
is_space = s.isspace()  # 判断字符串是否全为空格
print(is_start_with_hello)
print(is_digit)
print(is_alpha)
print(is_alnum)
print(is_space)

12、字符串填充与对齐

  • 使用ljust(), rjust(), center(), zfill()等方法

# 使用ljust(), rjust(), center(), zfill()等方法
s = "Hello"
print(s.ljust(10,'-')) # 字符在左边,右边以’-‘填充,一共长度为10
print(s.rjust(10,'-')) # 字符在右边,左边以’-‘填充,一共长度为10
print(s.center(10,'-')) # 填充10个空格,在中间
print(s.zfill(10)) # 填充10个0,在左边

总结

  • 希望对初学者有帮助

  • 致力于办公自动化的小小程序员一枚

  • 希望能得到大家的【一个免费关注】!感谢

  • 求个 🤞 关注 🤞

  • 此外还有办公自动化专栏,欢迎大家订阅:Python办公自动化专栏

  • 求个 ❤️ 喜欢 ❤️

  • 此外还有爬虫专栏,欢迎大家订阅:Python爬虫基础专栏

  • 求个 👍 收藏 👍

  • 此外还有Python基础专栏,欢迎大家订阅:Python基础学习专栏

http://www.yayakq.cn/news/769020/

相关文章:

  • 中国物流网站html静态网页制作案例
  • 可信赖的企业网站开发水产养殖网站模板源码
  • 教育网站制作价格计算机一级网页制作基础教程
  • 网站建设的七个步骤建设网站需要准备哪些内容
  • 重庆自助建网站企企业中企动力西安分公司
  • 2018年做网站赚钱吗pc 移动网站 模板
  • wordpress全站广告位做网站没有成本费用如何做账
  • 柳州做网站那家好如何将域名指向网站
  • 张家港网站制作建议找婚庆公司去什么网站
  • 网站底部流程wordpress 空搜索
  • 网站设计方案谁写如何成立一个网站
  • wordpress 整站打包字体WordPress
  • 常用的网站建设技术有免费微商城怎么开通?
  • 哪些ppt网站是免费的做网站最好的工具
  • 代理网站下载高端的网站设计公司
  • 企业网站货物查询怎么做邢台做网站地方
  • 新建文档怎么做网站wordpress 锚文本插件
  • 北京上地做网站湖北可以做网站方案的公司
  • 网站制作 代码photoshop制作网站海报
  • 建设网站简单教程引迈快速开发平台
  • 大型网站的设计网站正在备案中
  • 郑州网站建设培训短期班深圳知名设计公司
  • 网站建设分金手指专业十wordpress 短信登录
  • 做围棋题网站网络销售挣钱吗
  • 建设美团网站陕西省建设厅官网查询
  • 换网站了吗线上推广有哪些渠道
  • 网站管理的含义六安网页设计
  • 商城网站的建设方案在苏州注册公司需要多少钱
  • 河北住房和城乡建设厅网站成都住建局官网网上办事大厅
  • 网站安全建设需求分析报告网站建设技术员保密协议