How to intercept python string

angryTom
Release: 2020-02-28 12:06:47
Original
9379 people have browsed it

This article mainly introduces the method of string slicing (intercepting strings) in Python. The article introduces it in detail through sample code, which has certain reference learning value for everyone's study or work.

How to intercept python string

How to operate python string interception

String index diagram

How to intercept python string

String slicing means intercepting strings and taking substrings.

Recommended: Python video tutorial

String slicing method in Python

String [Start index: End index: step size]

Cut the string from the start index to the end index -1

When the step size is not specified, the step size is 1 String [start index:end index ]

Example: String interception

str = '12345678'
print str[0:1]  # 输出str位置0开始到位置1以前的字符
>> 1
print str[1:6] # 输出str位置1开始到位置6以前的字符
>> 23456
num = 18
str = '0000' + str(num) # 合并字符串
print str[-5:] # 输出字符串右5位
>> 00018
Copy after login

PHP Chinese website, a large number of Introduction to Programming tutorials, welcome to learn.

The above is the detailed content of How to intercept python string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!