Simple operation example of stepping adding and connecting python slices

  • 2021-07-13 05:52:54
  • OfStack

This paper describes the simple operation of stepping, adding and connecting python slices. Share it for your reference, as follows:

Step slicing:


#coding:utf-8
a="123456"
print a[::-1]
#output 654321
print a[::-2]
#output 642
print a[::2]
#output 135

String addition:


#coding:utf-8
a='123456789'
a1=[]
a1.extend(a[0:4])
a1.extend(a[4:])
print a1
#output ['1', '2', '3', '4', '5', '6', '7', '8', '9']

Connecting two string slices:


#coding:utf-8
__author__ = 'Administrator'
import string
a='python is nice'
b='mengtianwxs is a good boy'
print a[:6]+' and '+b[:11]
#output python and mengtianwxs

Readers interested in more Python related contents can check the topics of this site: "Summary of Python List (list) Operation Skills", "Summary of Python Coding Operation Skills", "Python Data Structure and Algorithm Tutorial", "Summary of Python Function Use Skills", "Summary of Python String Operation Skills", "Introduction and Advanced Classic Tutorial of Python" and "Summary of Python File and Directory Operation Skills"

I hope this article is helpful to everyone's Python programming.


Related articles: