当前位置:网站首页>字符串属性练习
字符串属性练习
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中存在,输出测试的结果边栏推荐
- Scala 基礎 (三):運算符和流程控制
- Differences between web testing and app testing
- Adding, deleting, checking and modifying stack - dynamic memory
- B1009 irony
- Oculusrifts and unity UI interaction (1) - Overview
- How to become a senior digital IC Design Engineer (1-1) Verilog coding Grammar: Introduction
- Com3529 test analysis
- Scala 基础 (三):运算符和流程控制
- Is there any risk in opening an account for Dongfang fortune stock? Is it safe for Dongfang fortune to open an account
- Wechat campaign auto like
猜你喜欢

Project R & D, what are the free brain mapping tools that are easy to use

How to use project Gantt chart to make project report

Large scale visual relationship understanding
Fundamentals of scala (3): operators and process control

如何成为一名高级数字 IC 设计工程师(4-5)脚本篇:Shell 脚本实现的文件比较操作
![[redis] set type](/img/97/0a83016e89316849c01072044f2124.png)
[redis] set type

I have summarized some experiences from the whole process of R & D platform splitting

【Redis】Hash类型

SystemVerilog-结构体(一)
![[redis] hash type](/img/8b/2585908318f5fe88b455323d3f392e.png)
[redis] hash type
随机推荐
Dialogue with opensea co creation Alex: we still only touch the tip of the iceberg of NFT capability | chain catcher
Crawler exercise (IV) -- IP address problem
How to encrypt the device
[redis] list type
想请教一下,如何选择券商?现在网上开户安全么?
[redis] sortedset type
Convert flat structure to tree structure
[redis] set type
How to encrypt anti copy program
When you complain about the roll, others have quietly begun to prepare for the golden three silver four
How to prevent virus
[C language] Fibonacci sequence and frog jumping steps (the most detailed elementary frog jumping steps)
Use code binding DataGridView control to display tables in program interface
Secondary encapsulation of storage (sessionstorage/localstorage) using TS
How to become a senior digital IC Design Engineer (4-2) script: file read / write operation realized by Verilog HDL code
C language course design - food warehouse management system
[redis] key hierarchy
直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!
【学习笔记】子集和问题
Why is it recommended that you choose the self research company as much as possible