Python's String cutting

Source: Internet
Author: User

The split () function in Python, typically used to slice and convert a string into a list.

First, function Description:

Split (): Syntax: Str.split (str= "", Num=string.count (str)) [n]

Splits a string. Slice the string by making a delimiter and return the segmented list of strings [list]

Parameter: str: delimiter, default is a space, but cannot be empty ("")

Num: Indicates the number of splits. If NUM is specified, it is split into n+1 substrings, and each string can be assigned to a new variable

[n]: Select the nth Shard, which is the nth string, calculated from 0.

1 #Coding=utf-82 Import Time3  fromSeleniumImportWebdriver4   5   6 classgetsubstring (object):7   8     defGet_search_result (self):9Driver =Webdriver. Chrome ()Ten Driver.maximize_window () OneDriver.implicitly_wait (8)   A    -Driver.get ('https://www.baidu.com')   -DRIVER.FIND_ELEMENT_BY_ID ('kw'). Send_keys ('Selenium')   theTime.sleep (1)   -search_result_string = Driver.find_element_by_xpath ("//*/div[@class = ' nums ')"). Text -         Print(search_result_string) -    +new_string = Search_result_string.split ('about') [1]#first cut to get XXXX, [1] for cutting the right part -         Print(new_string) +Last_result = New_string.split ('a') [0]#second cut, get the number we want [0] represents the left part of the cut reference parameter A         Print(Last_result) at    -    -GetString =getsubstring () -Getstring.get_search_result ()

Python's String cutting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.