python定义变量字符串_python -字符串变量

本文介绍了Python中字符串变量的使用,包括定义、长度计算、类型检查。通过示例展示了`find()`函数查找字符位置,以及如何遍历找到所有位置。还讲解了`split()`用于分割字符串,`strip()`用于去除特定字符,以及字符串的替换方法。最后提到了字符串到数组的转换以及数字操作。
摘要由CSDN通过智能技术生成

1. 字符串变量

# 注意引号的配对

a = "Hello, welcome to Python"

print("The string a is:", a)

print()

# 占位符

print("The length of this string is %d" % (a, len(a)))

print()

print("The type of a is", type(a))

The string a is: Hello, welcome to Python

The length of this string is 24

The type of a is

a = "Hello, welcome to Python"

print("The first character of a is %s" % a[0])

print("The first five characters of a are %s" % a[0:5])

print("The last character of a is %s" %a[-1])

print("The last two characters of a is %s"%a[-2:])

print("The last character of a is %s"%a[len(a)-1])

The first character of a is H

The first five characters of a are Hello

The last character of a is n

The last two characters

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值