题目:

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. 【题解】hdu4757 【TJOI2018】异或

    题目链接 题目大意:有一颗树,有点权,每次询问:一条路径\(x->y\)中与\(z\)异或的最大值,或是以\(x\)为根的子树中与\(y\)异或的最大值. 树剖--还是算了. 观察到,子树的\( ...

  2. Mysql的Sql语句优化

    在Mysql中执行Sql语句经常会遇到有的语句执行时间特别长的情况,出现了这种情况我们就需要静下心分析分析. 首先,我们需要确定系统中哪些语句执行时间比较长.这个可以使用Mysql的慢日志来跟踪.下面 ...

  3. TP5发送邮件

    1,前提去qq邮箱开启smtp 2,生成授权码 2,发送短信给 3,附上代码 贴上代码如下 <?phpnamespace app\mails\controller;use \think\Cont ...

  4. vue 下载jquery 下载layui-layer 下载vue-router

    1.下载jquery cmd:语句 npm install jquery 然后在main.js文件里面写 import $ from 'jquery' 2.下载layui-layer 在vue里面的l ...

  5. RFC 8684---TCP Extensions for Multipath Operation with Multiple Addresses

    https://datatracker.ietf.org/doc/rfc8684/?include_text=1 TCP Extensions for Multipath Operation with ...

  6. GML与KML的区别

    1.GML是基于XML的地理信息的传输.存储编码,它包括空间的和非空间的地理特征和地理范畴.GML是空 间数据编码.传输.存储.发布的国际标准KML是一个OGC标准 2.GML专注于地理信息的结构与内 ...

  7. 多测师讲解 _requests安装问题解决_高级讲师肖sir

    步骤一:"dos下新建一个pip文件,在文件下建一个pip.ini 文件,步骤二:文件中内容[global]index-url=http://mirrors.aliyun.com/pypi/ ...

  8. Rust之路(0)

    Rust--一个2012年出现,2015年推出1.0版本的"年轻"语言.在 2016 至 2018 年的 stack overflow 开发人员调查中,被评比为 "最受欢 ...

  9. 极简 Node.js 入门 - 5.2 url & querystring

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

  10. MeteoInfoLab脚本示例:FY-3C全球火点HDF数据

    FY-3C全球火点HDF数据包含一个FIRES二维变量,第一维是火点数,第二维是一些属性,其中第3.4列分别是火点的纬度和经度.下面的脚本示例读出所有火点经纬度并绘图.脚本程序: #Add data ...