当前位置:网站首页>字符串属性练习
字符串属性练习
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中存在,输出测试的结果边栏推荐
- Uniapp notes
- How to manage device authorization
- How to encrypt the device
- 基于 FPGA 的 RISC CPU 设计(4)关于项目的 36 个问题及其答案
- 【Redis】SortedSet类型
- 110. simple chat room 13: chat room server
- Fundamentals of scala (3): operators and process control
- Configurable FFT system design based on risc-v SOC (1) Introduction
- 大三下期末考试
- Who do you want to know when opening a stock account? Is it safe to open an account online now?
猜你喜欢

In simple terms, server intrusion prevention

Use code binding DataGridView control to display tables in program interface

How to use project Gantt chart to make project report

Interviewer: with the for loop, why do you need foreach??

如何成为一名高级数字 IC 设计工程师(4-3)脚本篇:C 语言实现的文件读写操作

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

Zhongyi technology resumed the review status of the gem IPO, and xuxiaofei no longer acted as a practicing lawyer

Adding, deleting, checking and modifying stack - dynamic memory
随机推荐
【网络通信学习笔记】Socket.IO的搭建和部署
Kubernetes: container resource requirements and constraints (constraints)
Why is it recommended that you choose the self research company as much as possible
Google Borg论文
干货丨微服务架构是什么?有哪些优点和不足?
Junior final exam
指南针手机股票开户哪个券商更安全更方便?
11 go Foundation: Interface
Wechat campaign auto like
[redis] list type
When you complain about the roll, others have quietly begun to prepare for the golden three silver four
C language course design - food warehouse management system
[redis] get to know redis for the first time
Koa 快速入門
[redis] data introduction & General Command & string type
How to encrypt the device
e. Difference between target and e.currenttarget
2022.02.15
同花顺究竟是如何开户?现在网上开户安全么?
How to become a senior digital IC Design Engineer (4-2) script: file read / write operation realized by Verilog HDL code