Python join()方法

join()方法语法:

str.join(sequence)

参数

  • sequence -- 要连接的元素序列。

返回值

返回通过指定字符连接序列中元素后生成的新字符串。

实例

#!/usr/bin/python
# -*- coding: UTF-8 -*- str = "-";
seq = ("a", "b", "c"); # 字符串序列
print str.join( seq );

以上实例输出结果如下:

a-b-c
故可用join将列表转为字符串

python strip()函数 介绍

函数原型

声明:s为字符串,rm为要删除的字符序列

s.strip(rm) 删除s字符串中开头、结尾处,位于 rm删除序列的字符
s.lstrip(rm) 删除s字符串中开头处,位于 rm删除序列的字符
s.rstrip(rm) 删除s字符串中结尾处,位于 rm删除序列的字符

注意:

1. 当rm为空时,默认删除空白符(包括'\n', '\r', '\t', ' ')

Python3 replace()方法

描述
replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。

语法
replace()方法语法:

str.replace(old, new[, max])
参数
old -- 将被替换的子字符串。
new -- 新字符串,用于替换old子字符串。
max -- 可选字符串, 替换不超过 max 次
返回值
返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。

题目描述:

第一次提交答案:

class Solution:
def reverse(self, x: int) -> int:
stx=str(x)
listx=list(stx)
if listx[0]=='-':
a=listx.pop(0)
listx.reverse()
listx.insert(0,a)
r="".join(listx)
a=int(r)
if a<(-2)**31:
return 0
else :
listx.reverse()
r="".join(listx)
a=int(r)
if a>(2**31-1):
return 0
return a

leetcood学习笔记-7的更多相关文章

  1. leetcood学习笔记-20

    python字符串与列表的相互转换   学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.s ...

  2. leetcood学习笔记-14*-最长公共前缀

    笔记: python if not   判断是否为None的情况 if not x if x is None if not x is None if x is not None`是最好的写法,清晰,不 ...

  3. leetcood学习笔记-54-螺旋矩阵

    题目描述: 第一次提交: class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: j,x = 0 ...

  4. leetcood学习笔记-35-二分法

    题目: 第一次提交; class Solution: def searchInsert(self, nums: List[int], target: int) -> int: for i in ...

  5. leetcood学习笔记-28-KMP*

    题目: 第一次提交: class Solution: def strStr(self, haystack: str, needle: str) -> int: if not len(needle ...

  6. leetcood学习笔记-27-移除元素

    题目: 第一次提交: class Solution: def removeElement(self, nums, val: int) -> int: for i in range(len(num ...

  7. leetcood学习笔记-26-删除排序数组中的重复项

    题目描述: 第一次提交: class Solution: def removeDuplicates(self, nums) -> int: for i in range(len(nums)-1, ...

  8. leetcood学习笔记-21**-合并两个有序链表

    题目描述: 方法一: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.va ...

  9. leetcood学习笔记-13

    错误记录 class Solution: def romanToInt(self, s: str) -> int: d = {'I':1,'V':5,'X':10,'L':50,'C':100, ...

  10. leetcood学习笔记-9

    题目描述 方法一:转换为字符串 class Solution: def isPalindrome(self, x: int) -> bool: if x<0: return False e ...

随机推荐

  1. Jenkins配置定时构建项目

    general: 源码管理: 构建触发器: 构建后操作:

  2. c++后台开发面试常见知识点总结(六)算法手写

    链表倒转  leetcode-206 连续子数组最大和问题(和最大的连续子序列的和)   leetcode-53 输出字符串中最长的回文子串长度?  leetcode-5 一个字符串,求最长无重复子串 ...

  3. mybatis generator 使用方法

    环境: ubuntu   eclipse maven 一. 简介 mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,快速生成mapper和xml文件以及pojo 二. ...

  4. 编译自己的jdk(使用openJDK源码编译jdk )

    找到openjdk网站(http://hg.openjdk.java.net/) 选择需要编译的版本,浏览readme文件,有获取源码及编译步骤 CentOS-7-x86_64-DVD-1804.is ...

  5. C# GDI+简单绘图

    一.使用Pen画笔 Pen的主要属性有: Color(颜色),DashCap(短划线终点形状),DashStyle(虚线样式),EndCap(线尾形状), StartCap(线头形状),Width(粗 ...

  6. hdu 4609 3-idiots(FFT+去重处理)

    3-idiots Problem Description King OMeGa catched three men who had been streaking in the street. Look ...

  7. JDK 9 发布仅数月,为何在生产环境中却频遭嫌弃?

    千呼万唤始出来,在经历了整整一年的跳票之后,Java 9 终于在 9 月 21 日拨开云雾,露出真正的面目.对众多 Java 程序员来说,这一天无疑是一个重大的日子,首先 Java 开发者们再也不用羡 ...

  8. pythy标准库之Tkinter(hello world窗口显示)

    Tkinter :Tkinter,python内置的图形开发库GUI python3.x中: import tkinter #注意不要写成Tkinter, 一.用tkinter创建hello worl ...

  9. hci_ceph安装过程

    auto loiface lo inet loopbackauto enp50s0f0iface enp50s0f0 inet static address 192.168.1.6 netmask 2 ...

  10. 77、tensorflow手写识别基础版本

    ''' Created on 2017年4月20日 @author: weizhen ''' #手写识别 from tensorflow.examples.tutorials.mnist import ...