当前位置:网站首页>返回文件名问题
返回文件名问题
2022-08-02 06:02:00 【算法与编程之美】
1 问题
请写一个函数,该函数可以返回字符串“Score.excel”的文件名。
2 方法
首先,我们先定义一个函数,给定一个n作为“计数器”再利用循环遍历,直到遍历到“.”;再利用切片,我们就可以得到所需的文件名。
3 实验结果与讨论
通过实验、实践等证明提出的方法是有效的,是能够解决开头提出的问题。
代码清单 1
| def my_0(x): n = 0 for i in str(x): n = n+1 if i == '.': break return str(x)[:n-1] d = 'Score.excel' print(my_0(d)) |
4 结语
本文主要介绍的为返回文件名问题,解决该问题对于我们寻找文件名有极大帮助,我们可以轻松的利用此程序来找到所需要的文件名,极大地加快了我们工作的效率。
边栏推荐
- 蚂蚁三面:MQ 消息丢失、重复、积压问题,有哪些解决方案?
- Dataset: A detailed guide to the download link collection of commonly used datasets in machine learning
- MySQL - 多表查询与案例详解
- zabbix email alarm and WeChat alarm
- MySQL union query (multi-table query)
- 振兴农村循环经济 和数链串起农业“生态链”
- How does abaqus quickly import the assembly of other cae files?
- HCIP BGP Comprehensive Experiment Establishing peers, route reflectors, federation, route announcement and aggregation
- zabbix auto-discovery and auto-registration
- 推出 Space On-Premises (本地部署版) Beta 版!
猜你喜欢

BGP+MPLS Comprehensive Experiment

Xgboost报错 ValueError: Invalid shape: (1650, 2) for label

MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)

Nacos安装详细过程

How to install the specified version package with NPM and view the version number

Reverse resolve dns server

The installation of NPM, CNPM

(笔记整理未完成)【图论】图的遍历

宝塔+FastAdmin 404 Not Found

abaqus如何快速导入其他cae文件的assembly?
随机推荐
nodejs的安装和全局配置(超详细哦)
MarkDown Formula Instruction Manual
Nacos安装详细过程
(Notes are not completed) [Graph Theory] Traversal of graphs
Node installation and environment variable configuration
[Cartoon] 2021 full score programmer behavior comparison table (latest version)
MySQL(3)
Pagoda+FastAdmin 404 Not Found
一文搞懂C操作符
MySQL Advanced SQL Statements (2)
Not annotated parameter overrides @NonNullApi parameter
MySQL 23道经典面试吊打面试官
pointer arithmetic in c language
Dataset: A detailed guide to the download link collection of commonly used datasets in machine learning
Kingdee International: Lost in half a year and last year, how does the business model of frantically burning money continue
abaqus如何快速导入其他cae文件的assembly?
MySQL Index Common Interview Questions (2022 Edition)
CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
Py's mlxtend: a detailed guide to the introduction, installation, and usage of the mlxtend library
Servlet