题目:

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?(字母结尾)的更多相关文章

  1. java string,需要进行首字母大写改写

    java string,需要进行首字母大写改写,网上大家的思路基本一致,就是将首字母截取,转化成大写然后再串上后面的,类似如下代码 //首字母大写     public static String c ...

  2. 【Kata Daily 190903】String incrementer(字符串增量器)

    原题: Your job is to write a function which increments a string, to create a new string. If the string ...

  3. 【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 ...

  4. 【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 ...

  5. C#查找以某个字母开头另一字母结尾的字符串

    using System; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { ...

  6. 【leetcode80】Reverse Vowels of a String(元音字母倒叙)

    题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a ...

  7. 791. Custom Sort String字符串保持字母一样,位置可以变

    [抄题]: S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S wa ...

  8. C++ string 是否以‘\0’结尾 讨论

    转载https://blog.csdn.net/qq_31930499/article/details/80374310 之前在某篇文章中看到,C语言字符串是以’\0’结尾的,但是C++string类 ...

  9. 【Kata Daily 190929】Password Hashes(密码哈希)

    题目: When you sign up for an account somewhere, some websites do not actually store your password in ...

随机推荐

  1. Arduino control Eeprom by IIC method of using device address in Arduino

    参考: 1.https://www.arduino.cc/ 2.https://www.arduino.cc/reference/en/ 3.https://www.arduino.cc/en/Ref ...

  2. shiro入门学习--授权(Authorization)|筑基初期

    写在前面 经过前面的学习,我们了解了shiro中的认证流程,并且学会了如何通过自定义Realm实现应用程序的用户认证.在这篇文章当中,我们将学习shiro中的授权流程. 授权概述 这里的授权指的是授予 ...

  3. Java安全之Commons Collections1分析(二)

    Java安全之Commons Collections1分析(二) 0x00 前言 续上篇文,继续调试cc链.在上篇文章调试的cc链其实并不是一个完整的链.只是使用了几个方法的的互相调用弹出一个计算器. ...

  4. java进阶(26)--ForEach

    JDK5.0后新特性 一.普通for循环

  5. 树型大融合——NOIP提高组2015 D1T3 【运输计划】

    下午用一个小时看了一下树上差分,打了个差分模板,A了3题,真的爽! 题目描述: 公元2044 年,人类进入了宇宙纪元. L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 ...

  6. git 查看本地分支和切换本地分支的命令

    查看本地分支,和当前所在的分支 git branch -vv git checkout developer 切换到developer分支

  7. hugo官方相关文档地址

    +++ date="2020-10-17" title="hugo官方相关文档地址" tags=["hugo"] categories=[& ...

  8. zookeeper动态添加/删除集群中实例(zookeeper 3.6)

    一,用来作为demo操作的zookeeper集群中的实例: 机器名:zk1 server.1=172.18.1.1:2888:3888 机器名:zk2 server.2=172.18.1.2:2888 ...

  9. 跟我一起学Redis之看完这篇比常人多会三种类型实战(又搞了几个小时)

    前言 对于Redis而言,很多小伙伴只关注其关键的五大基础类型:string.hash.list.set.sorted set(有序集合),其实还有三种特殊类型在很多应用场景也比较适合使用,分别是:b ...

  10. 2.通过QOpenGLWidget绘制三角形

    参考:1.opengl绘制三角形 1.QOpenGLWidget的早先版本 QGLWidget是遗留Qt OpenGL模块的一部分,和其他QGL类一样,应该在新的应用程序中避免使用.相反,从Qt 5. ...