当前位置:网站首页>返回文件名问题
返回文件名问题
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 结语
本文主要介绍的为返回文件名问题,解决该问题对于我们寻找文件名有极大帮助,我们可以轻松的利用此程序来找到所需要的文件名,极大地加快了我们工作的效率。
边栏推荐
- CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
- MySQL高级-MVCC(超详细整理)
- MySQL classic 50 practice questions and the most detailed analysis of the whole network
- Nacos installation configuration and single-machine deployment tutorial
- View source and switch mirrors in two ways: npm and nrm
- Mining game (C language)
- Dataset:机器学习中常用数据集下载链接集合之详细攻略
- Two good php debug tutorials
- mysql高阶语句(一)
- MySQL高级语句(一)
猜你喜欢
About the local server problem after ue4.27 pixel streaming package
Go inside the basic knowledge
Clapper that can interact with the audience in real time
MySQL Index Common Interview Questions (2022 Edition)
Write implicit join on view with jOOQ 3.14 synthetic foreign key
Kingdee International: Lost in half a year and last year, how does the business model of frantically burning money continue
ASP.NET Core Web API 幂等性
rhce homework
HCIP day 3 experiment
Toolbox App 1.25 New Features at a Glance | Version Update
随机推荐
CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
Py's mlxtend: a detailed guide to the introduction, installation, and usage of the mlxtend library
node安装及环境变量配置
aTrust项目的相关操作与分享
DNS resolution process
MySQL high-level --- storage engine, index, lock
Node installation and environment variable configuration
chrome plugin development guide
Detailed explanation of 9 common reasons for MySQL index failure
MySQL 5.7 安装教程(全步骤、保姆级教程)
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
Dataset: A detailed guide to the download link collection of commonly used datasets in machine learning
punch day05
MySql统计函数COUNT详解
HCIP 第三天实验
Write implicit join on view with jOOQ 3.14 synthetic foreign key
npm does not recognize the "npm" item as the name of a cmdlet, function, script file, or runnable program.Please check the spelling of the name, and if the path is included, make sure the path is corr
c语言指针运算
Leetcode周赛304
View source and switch mirrors in two ways: npm and nrm