当前位置:网站首页>字符串属性练习
字符串属性练习
2022-06-29 02:12:00 【长街395】
描述
字符串的基本操作
| 操作符 | 描述 |
|---|---|
| s + t | 拼接两个序列 s 和 t |
| s * n 或n * s | 将序列s重复n次生成新序列 |
| s[i] | 索引,返回序列s的第i项 |
| s[start:end[:step]] | 切片,返回序列 s 从start到end (不包括end )的步长为step的字符生成新的序列,step缺省时,步长为1,返回序号从start到end的子序列。 |
| len(s) | 返回序列s的长度(包含元素的个数) |
| min(s,*[,key, default]) | 返回序列 s的最小值,key关键字缺省时按元素值比较 |
| max(s,*[,key, default]) | 返回序列 s的最大值,key关键字缺省时按元素值比较 |
| s.count(x) | 序列s中x的个数 |
| s.index(x[, i[, j]]) | 序列中第一个x的索引值,i值表示从索引i处开始查找x,j表示x查找范围在i和j之间。 |
| x in s | 如果序列x与序列s中的任一子序列相等,返回True,否则返回False;当x与s的元素相等时返回True,否则返回False。 |
| x not in s | 如果序列x与序列s中的任何子序列都不相等,返回True,否则返回False |
请参考上表,根据注释的要求完成模板程序。
id = input() # 输入学号
name = input() # 输入姓名
print(id,name,sep='') # 输出学号姓名,中间无空格
print(name*5) # 重复输出姓名5遍,中间无空格
s = '人都可以走路,也就是有一个走路方法' # 这是一个字符串
n=int(input()) # 接收一个整数输入n
print(s[n]) # 输出字符串s中序号为n的字符
print(s[0::2])# 输出字符串s中序号为偶数的字符
print(s[::-1]) # 将字符串逆序输出
print(len(s)) # 输出字符串s的长度
print(len(s[n::])) # 输出字符串s中从序号n到字符串结尾包含的字符个数(包括序号为n的字符)
print(s.count('路')) # 输出字符串s中子字符串‘走路’的个数
print(s.find('走')) # 输出字符串s中字符‘走’第一次出现的位置序号
test = input() # 输入一个字符串
print(test in s) # 测试test是否在s中存在,输出测试的结果边栏推荐
- 【Redis】初识 Redis
- Blog publishing test 3
- RISC CPU design based on FPGA (4) 36 questions about the project and their answers
- A full screen gesture adaptation scheme
- Which brokerage is safer and more convenient to open a stock account for big smart phones?
- Ambiguity between 0 and 1
- I have summarized some experiences from the whole process of R & D platform splitting
- Use code binding DataGridView control to display tables in program interface
- Kubernetes: container resource requirements and constraints (constraints)
- 指南针手机股票开户哪个券商更安全更方便?
猜你喜欢
![[redis] key hierarchy](/img/ab/a5d3bb61b4571966d0f47037af4f41.png)
[redis] key hierarchy

Koa 快速入門
![[redis] set type](/img/97/0a83016e89316849c01072044f2124.png)
[redis] set type
![[redis] list type](/img/c7/adec2aaea50d69a0aed95bfe683b9e.png)
[redis] list type
![[understanding of opportunity -33]: seeing is not necessarily true. Most of the time,](/img/60/703a5bc3038d28bcf812415032f240.jpg)
[understanding of opportunity -33]: seeing is not necessarily true. Most of the time, "seeing is false"
![[MySQL practice of high concurrency, high performance and high availability of massive data -9] - transaction concurrency control solutions lbcc and mvcc](/img/62/77c2274db4f92ad1d88901e149251c.jpg)
[MySQL practice of high concurrency, high performance and high availability of massive data -9] - transaction concurrency control solutions lbcc and mvcc

瀑布型项目管理最常用的10个小工具,可以自由搭建使用

Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin

OculusRiftS与Unity.UI的交互(1)-总览

【Redis】List类型
随机推荐
How to encrypt the device
Scala 基础 (三):运算符和流程控制
如何成为一名高级数字 IC 设计工程师(3-5)工具篇:SpyGlass 技术
QT basics tutorial: qstringlist
Smart world 2030
[learning notes] subsets and questions
Wechat campaign auto like
请问etf基金是否靠谱,安全吗
KOA Quick Start
How to become a senior digital IC Design Engineer (4-2) script: file read / write operation realized by Verilog HDL code
[redis] sortedset type
Business system anti-virus
C language course design - food warehouse management system
How to prevent virus
Understand flex layout in an article
基于 FPGA 的 RISC CPU 设计(4)关于项目的 36 个问题及其答案
How to become a senior digital IC Design Engineer (5-1) theory: clock technology, reset Technology
Redis data migration (III)
Which is the best billing method for okcc call center
网上联系客户经理办理炒股开户安全吗?