Python full stack development-Day3 string, python-day3 string

Source: Internet
Author: User

Python full stack development-Day3 string, python-day3 string
Full-stack python development-Day3 string1. Start string learning based on the following points:

#1. Basic usage

1. Purpose

# First, the main function of a string: name, gender, nationality, address, and other description information

2. Definition Method

Contains a string of characters in single, double, double, and triple quotes.

 

3. Common Operations + Built-in Methods

# Preferred operations:

#1. index value (Forward fetch + reverse fetch): Only available

#2. Slice (regardless of tail, step size)

#3. Length len

#4. member operations in and not in

#5. Remove blank strip

#6. split

#7. Loop


# Ii. Summary of this type
1. Store one value or multiple values
Only one value can be saved.
Multiple values can be saved. What type can a value be stored?
2. ordered or disordered
3. variable or immutable
!!! Variable: The value changes, and the id remains unchanged. Variable = non-hash
!!!Immutable: The value changes, and the id changes. Immutable = hash

2. start to understand the problem String
# Definition: in single quotation marks, double quotation marks, and triple quotation marks, name = 'qianduoduo' name = "qianduoduo" name = '''qianduoduo' ''is composed of a string of characters # The following operations are preferred: #1. Take the index value (forward and reverse ): only name = "qianzeliang" name [0] # value: "q" name [-1] # value: "g" #2. Slice (skip the tail and step size) name = "qianzeliang" name [] # value: "anzeli" name [] # value: "azl" #3. Length: lenname = "qianzeliang" len (name) #11 #4. member operations in and not inname = "qianzeliang" "q" in name # True "q" not in name # False #5. Remove blank stripname =" qianzeliang "name. strip () # value: qianzeliang #6. Split splitname = "qian: ze: liang" name. split (":") # value: ["qian", "ze", "liang"] #7. Cyclic msg = 'qianduoduo' I = 0 while True: if I <len (msg): print (msg [I]) I + = 1 else: break # operations to be mastered #1. strip, lstrip, rstrip #2. lower, upper #3, startswith, endswith #4, format three methods #5, split, rsplit #6, join #7, replace #8, isdigit # stripname = '* egon **' print (name. strip ('*') print (name. lstrip ('*') print (name. rstrip ('*') # lower, uppername = 'egon' print (name. lower () print (name. upper () # startswith, endswithname = 'Alex _ SB 'print (name. endswith ('SB ') print (name. startswith ('Alex ') # three methods of format: res = '{}{}{}'. format ('egon', 18, 'male') res = '{1} {0} {1 }'. format ('egon', 18, 'male') res = '{name} {age} {sex }'. format (sex = 'male', name = 'egon', age = 18) # splitname = 'root: x: 0: 0:/root: /bin/bash 'print (name. split (':') # The default Delimiter is space name = 'C:/a/B/C/d.txt '# Only the top-level directory print (name. split ('/', 1) name = 'a | B | C' print (name. rsplit ('|', 1) # Start from the right to split # jointag = ''print (tag. join (['egon', 'say', 'Hello', 'World']) # iteratable objects must be strings # replacename = 'Alex say: I have one tesla, my name is alex 'print (name. replace ('Alex ', 'SB', 1) # isdigit: you can determine the bytes and unicode types, is the most commonly used method for determining whether the character is a "Number" age = input ('>>:') print (age. isdigit ())
Iii. Summary

1. Only one value can be saved.

2. Order 3. unchangeable: The value changes, and the id changes. Immutable = hash

 

 

 

 

 

 

Other operations (learn more) #1. find, rfind, index, rindex, count #2, center, ljust, exactly ust, zfill #3, expandtabs #4, captalize, swapcase, title #5. is digital Series #6. is others # find, rfind, index, rindex, countname = 'egon say hello 'print (name. find ('O',) # ignore the tail of the gu header. If no result is found,-1 is returned and no error is returned. If yes, the index is displayed # print (name. index ('E', 2, 4) # Same as above, but print (name. count ('E', 1, 3) # ignore the tail of the gu header. If no range is specified, search for all # center, ljust, must, zfillname = 'egon' print (name. center (30, '-') print (name. ljust (30, '*') print (name. must ust (30, '*') print (name. zfill (50) # Fill with 0 # expandtabsname = 'egon \ thello 'print (name) print (name. expandtabs (1) # captalize, swapcase, titleprint (name. capitalize () # print (name. swapcase () # case flip msg = 'egon say Hi' print (msg. title () # uppercase letters of each word # is digital Series # In python3, num1 = B '4' # bytesnum2 = u'4' # unicode, in python3, unicodenum3 = '4' # Chinese numeric num4 = 'iv' # roman numerals # isdigt: bytes, unicodeprint (num1.isdigit () # Trueprint (num2.isdigit ()) # Trueprint (num3.isdigit () # Falseprint (num4.isdigit () # False # isdecimal: uncicode # bytes type without isdecimal method print (num2.isdecimal () # Trueprint (num3.isdecimal ()) # Falseprint (num4.isdecimal () # False # isnumberic: unicode, Chinese digit, Roman digit # print (num2.isnumeric () for the bytes type without isnumberic method # Trueprint (num3.isnumeric ()) # Trueprint (num4.isnumeric () # True # The three cannot determine the floating point number num5 = '4. 3 'print (num5.isdigit () print (num5.isdecimal () print (num5.isnumeric () ''' Summary: The most common is isdigit, which can be used to determine the bytes and unicode types, this is also the most common digital Application Scenario. If you want to determine a Chinese or roman number, you need to use isnumeric ''' # is other print ('=> ') name = 'egon123 'print (name. isalnum () # A string consists of letters or numbers (print (name. isalpha () # A string consists of only letters print (name. isidentifier () print (name. islower () print (name. isupper () print (name. isspace () print (name. istitle ())

 

 

 

 

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.