【Kata Daily 190916】String end with?(字母结尾)
题目:
Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).
Examples:
solution('abc', 'bc') # returns true
solution('abc', 'd') # returns false
解题办法:
def solution(string, ending):
# your code here...
if ending == '':
return True
else:
a = string[::-1][:len(ending)][::-1]
if a == ending:
return True
else:
return False
最佳解题办法:
def solution(string, ending):
return string.endswith(ending)
知识点:
1、string.endswith(str):使用endswith可以判断是否以某个字符串结尾
【Kata Daily 190916】String end with?(字母结尾)的更多相关文章
- java string,需要进行首字母大写改写
java string,需要进行首字母大写改写,网上大家的思路基本一致,就是将首字母截取,转化成大写然后再串上后面的,类似如下代码 //首字母大写 public static String c ...
- 【Kata Daily 190903】String incrementer(字符串增量器)
原题: Your job is to write a function which increments a string, to create a new string. If the string ...
- 【Kata Daily 190917】Numericals of a String(字符出现的次数)
题目: You are given an input string. For each symbol in the string if it's the first character occuren ...
- 【Kata Daily 190912】Alphabetical Addition(字母相加)
题目: Your task is to add up letters to one letter. The function will be given a variable amount of ar ...
- C#查找以某个字母开头另一字母结尾的字符串
using System; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { ...
- 【leetcode80】Reverse Vowels of a String(元音字母倒叙)
题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a ...
- 791. Custom Sort String字符串保持字母一样,位置可以变
[抄题]: S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S wa ...
- C++ string 是否以‘\0’结尾 讨论
转载https://blog.csdn.net/qq_31930499/article/details/80374310 之前在某篇文章中看到,C语言字符串是以’\0’结尾的,但是C++string类 ...
- 【Kata Daily 190929】Password Hashes(密码哈希)
题目: When you sign up for an account somewhere, some websites do not actually store your password in ...
随机推荐
- matlab一个figure画多个子图,和多个figure画多个图。
参考:https://blog.csdn.net/xiaotao_1/article/details/79024488 1,一个figure画多个子图: figure(10) % define fig ...
- Arduino各开发板
参考来源:https://www.arduino.cn/thread-42417-1-1.html 查了好久,发现除了奈何等等几位大神总结过arduino各板子之间的性能.差异,没有很新的分析文章,在 ...
- AE2018简单的编辑
来源:https://jingyan.baidu.com/article/1876c8525cf522890a137651.html Ae 2018 怎样锁定图层,阻止对图层进行编辑? 听语音 原创 ...
- Go 接口类型
接口作用 Go语言中的接口是一种类型,类似于Python中的抽象基类. Go语言中使用接口来体现多态,是duck-type的一种体现. 如,只要一个东西会叫,会走,那么我们就可以将它定义为一个动物的接 ...
- Oracle误操作 数据恢复
SELECT * FROM v$sqlarea //查询最近sql记录 SELECT r.FIRST_LOAD_TIME,r.* FROM v$sqlarea r ORDER BY r.FIRST_L ...
- Azure Cosmos DB (三) EF Core 操作CURD
一,引言 接着上一篇使用 EF Core 操作 Azure CosmosDB 生成种子数据,今天我们完成通过 EF Core 实现CRUD一系列功能.EF Core 3.0 提供了CosmosDB 数 ...
- openstack 高可用环境部署(8节点)(一)
- day30 Pyhton 面向对象 反射
@property # 例1 - 1 (某一个属性如果是通过计算得来的,那么计算的过程写在方法里,把这个方法伪装成属性) from math import pi # class Circle: # d ...
- day16 Pyhton学习
1.range(起始位置) range(终止位置) range(起始,终止位置) range(起始,终止,步长) 2.next(迭代器) 是内置函数 __next__是迭代器的方法 g.__next_ ...
- Termux基础教程(一):技能部署
Termux基础教程 by CUCI Termux 是一个 Android 下一个高级的终端模拟器,开源且不需要 root,支持 apt 管理软件包,十分方便安装软件包,完美支持 Python. PH ...