Python learning [string]

Source: Internet
Author: User

3. String
1. Characters: Single text symbol
2. String: Ordered sequence of characters
string of contents enclosed by ' " '" ""

Index: A row of numbers. The subscript of the character index at the first position of the reaction starts at 0. Use [] to get data
slices: [Start:end:step]
Gu Tou Regardless of the tail
Step: Step size. If it is + from left to right. If yes-1 for each n from right to left

3. Common Operation methods:
1. Upper () converted to uppercase. When ignoring the case
2. Strip () remove left and right blank user input content to go blank
3. Replace (old, new) string substitution
4. Split () The result of the cut is List
5. StartsWith () Decide whether to start with xxx
6. Find () Lookup
7. IsDigit () Judge whether it is a number composition
8. Len () to find the length. Built-in functions

Practice:

# ""
# 1. Variable name = "AleX leNb" do the following:
# 1) Remove the space on both sides of the value corresponding to the name variable and output the processing result
# 2) Remove "Al" to the left of the name variable and output processing results
# 3) Remove the "Nb" from the right of the name variable and output the processing result
# 4) Remove the "a" and the Last "B" at the beginning of the name variable and output the processing result
# 5) Determine if the name variable starts with "Al" and outputs the result
# 6) Determine if the name variable ends with "Nb" and outputs the result
# 7) Replace All "L" in the value corresponding to the name variable with "P", and output the result
# 8) Replace the first "L" in the value corresponding to the name variable with "P", and output the result
# 9) splits the value corresponding to the name variable according to all "L" and outputs the result.
# 10) splits the value corresponding to the name variable according to the "L" and outputs the result.
# 11) Change the value of the name variable to write and output the result
# 12) Change the value of the name variable to write and output the result
# 13) The value of the name variable corresponding to the word? " A "write, and output the result
# 14) Determine the value word corresponding to the name variable? " L "appears, and outputs the result
# 15) If you determine the value of the name variable corresponding to the first four bits "L" appears, and output the result
# 16) find the index corresponding to "N" from the value corresponding to the name variable (if no error is found), and output the result
# 17) find the index corresponding to "N" from the value corresponding to the name variable (return-1 if not found) output result
# 18) find the index corresponding to "X le" from the value corresponding to the name variable and output the result
# 19) Please output the 2nd character of the value corresponding to the name variable?
# 20) Please output the first 3 characters of the value corresponding to the name variable?
# 21) Please output the name variable corresponding to the value of the second 2 characters?
# 22) Please output the value of the name variable corresponding to the index position of "E"?
# ""
# name= "AleX leNb"
# 1) Remove the space on both sides of the value corresponding to the name variable and output the processing result
# Name1=name.strip ()
# Print (name1)
#
# 2) Remove "Al" to the left of the name variable and output processing results
# Name1=name.strip ("Al")
# Print (name1)
#
# 3) Remove the "Nb" from the right of the name variable and output the processing result
# Name1=name.rstrip ("Nb")
# Print (name1)
#
# 4) Remove the "a" and the Last "B" at the beginning of the name variable and output the processing result
# Name1=name.lstrip ("a")
# Name2=name1.rstrip ("B")
# Print (name2)
#
# 5) Determine if the name variable starts with "Al" and outputs the result
# Name1=name.startswith ("Al")
# Print (name1)
#
# 6) Determine if the name variable ends with "Nb" and outputs the result
# Name1=name.endswith ("Nb")
# Print (name1)
#
# 7) Replace All "L" in the value corresponding to the name variable with "P", and output the result
# Name1=name.replace ("L", "P")
# Print (name1)
#
# 8) Replace the first "L" in the value corresponding to the name variable with "P", and output the result
# Name1=name.replace ("L", "P", 1)
# Print (name1)
#
# 9) splits the value corresponding to the name variable according to all "L" and outputs the result.
# Name1=name.split ("L")
# Print (name1)
#
# 10) splits the value corresponding to the name variable according to the "L" and outputs the result.
# Name1=name.split ("L", 1)
# Print (name1)
#
# 11) Change the value of the name variable to write and output the result
# name1=name.upper ()
# Print (name1)
#
# 12) Change the value of the name variable to write and output the result
# name1=name.lower ()
# Print (name1)
#
# 13) The value of the name variable corresponding to the word? " A "write, and output the result
# name1=name.capitalize ()
# Print (name1)
#
# 14) Determine the value word corresponding to the name variable? " L "appears, and outputs the result
# Name1=name.count ("L")
# Print (name1)
#
# 15) If you determine the value of the name variable corresponding to the first four bits "L" appears, and output the result
# Name1=name[0:5].count ("L")
# Print (name1)
#
# 16) find the index corresponding to "N" from the value corresponding to the name variable (if no error is found), and output the result
# Name1=name.index ("N")
# Print (name1)
#
# 17) find the index corresponding to "N" from the value corresponding to the name variable (return-1 if not found) output result
# Name1=name.find ("N")
# Print (name1)
#
# 18) find the index corresponding to "X le" from the value corresponding to the name variable and output the result
# Name1=name.find ("X le")
# Print (name1)
#
# 19) Please output the 2nd character of the value corresponding to the name variable?
# Name1=name[1]
# Print (name1)
#
# 20) Please output the first 3 characters of the value corresponding to the name variable?
# Name1=name[:3]
# Print (name1)
#
# 21) Please output the name variable corresponding to the value of the second 2 characters?
#
# name1=name[-2:]
# Print (name1)
#
# 22) Please output the value of the name variable corresponding to the index position of "E"?
#
# Name1=name.find ("E")
# Print (name1)
# ""
# There is a string s = "123a4b5c"
# 1) through to s tangent? form a new string s1,s1 = "123"
# 2) through to S tangent? form a new string s2,s2 = "a4b"
# 3) through to s tangent? form a new string s3,s3 = "1345"
# 4) through to S tangent? form string s4,s4 = "2ab"
# 5) through to S tangent? form string s5,s5 = "C"
# 6) through to S tangent? form string s6,s6 = "Ba2"
#
# ""
# s = "123a4b5c"
# 2.1) through to S tangent? form a new string s1,s1 = "123"
# S1=s[0:3]
# Print (S1)
#
# 2.2) through to s tangent? form a new string s2,s2 = "a4b"
# S1=s[3:6]
# Print (S1)
#
# 2.3) through to S tangent? form a new string s3,s3 = "1345"
# s1=s[::2].split ()
# Print (S1)
#
# 2.4) through to S tangent? form string s4,s4 = "2ab"
# s1=s[1:6:2].split ()
# Print (S1)
#
# 2.5) through to S tangent? form string s5,s5 = "C"
# S1=s[-1]
# Print (S1)
#
# 2.6) through to S tangent? form string s6,s6 = "Ba2"
#
# S1=s[-3:-8:-2]
# Print (S1)

Python learning [string]

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.