Python14 period (2018.7.4)

Source: Internet
Author: User
Tags set set

1. Encoding
        1. The earliest computer encoding is ASCII. American created. Contains the English alphabet (uppercase letters, lowercase letters). Special characters such as numbers, punctuation, etc. [ email protected]#$%
            128 code bit 2**7 A 2**8
            8-bit is added on this basis. 1 bytes (byte)
         2. GBK GB code 16 bit. 2 bytes (double-byte characters)
        3. Unicode    32-bit, 4 bytes
         4. utf-8:  English   8 bit 1 bytes
                 European Characters 16bit 2 bytes
                 Chinese 24bit  3 bytes

8bit = 1 byte
1024x768 byte = > 1kb
1024x768 = 1MB
1024MB = 1GB
1024GB = > 1TB


2. Overview of basic data types
int integer
STR string, storing a small amount of data
BOOL Boolean
List, ["Tai Yang elder brother", "Dongyang elder brother",]
Tuple tuples. Read-only list, cannot be changed
Dict dictionary; A pair of stored data. Key:value {"Zhao Yang": "Tai Yang elder brother", ' Jay ': "Jay Chou"}
Set set. Store non-duplicated content

    3. int, bool, str
        int method operation:
             bit_length () to find the binary length
         bool: type conversion
            1. What you want to convert into. I'm going to wrap it up with something.
            2. False with NULL, true without empty
        STR
             1. STR index and slice:
                Index: Starting subscript is 0 (left to right), (-1) right-to-left
                 slices: s[start position: End position: Step]
                     Features: Gu Tou disregard tail

2. Common operations for strings: common methods
The string is immutable.
1. Upper () converted to uppercase
2. Strip () Remove space
3. Replace () replacement
4. Split () cut
5. Format () formatted output
6. StartsWith () Decide whether to start with XXX
7. Find (). No return-1 found
8. Len () built-in functions. Direct use. To find the length of a string without a point operation
3. Iteration
The for variable in can iterate over the object:
Loop body
Else

Example: #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" to 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 all the first "L" and outputs the result.
# 11) Capitalize the value corresponding to the name variable and output the result
# 12) Lowercase the value corresponding to the name variable and output the result
# 13) Capitalize the first letter "a" of the value corresponding to the name variable and output the result
# 14) Determine the value of the name variable corresponding to the letter "L" appears several times, and output the result
# 15) If you determine the value of the name variable corresponding to the first four bits "L" appears several times, 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 name variable corresponding to the value of name = "E" in "AleX leNb" where is the index?
#1 print (Name.strip ())
#2 Print (Name.strip (' al ')) #strip () remove spaces and elements from both ends
#3 Print (Name.replace (' Nb ', ')) #将Nb替换成空的
#4 Print (Name.strip (' AB '))
#5 Print (Name.startswith (' al '))
#6 Print (Name.endswith (' Nb '))
#7print (Name.replace (' l ', ' P '))
#8 Print (Name.replace (' l ', ' P ', 1))
# Print (Name.split (' l '))
# Print (Name.split (' l ', 1))
# #11print (Name.upper ())
#12print (Name.lower ())
#13print (Name.replace (' A ', ' a '))
# Print (Name.count (' l '))
# Print (Name.count (' l ', 4))
# Print (Name.index (' N '))
# Print (Name.find (' N '))
# Print (Name.find (' X le '))
# print (name[1])
# print (Name[0:3])
# print (name[-2:])
# name = "AleX leNb" # 22) Please output the value of the name variable corresponding to the index position of "E"?
# count = 0
# for I in Name:
# if i = = ' E ':
# Print (i)
# count + = 1
# 2. There is a string s = "123a4b5c"
# 1) by forming a new string for the S-slice s1,s1 = "123"
# 2) by forming a new string for the S-slice s2,s2 = "a4b"
# 3) by forming a new string for the S-slice S3,S3 = "1345"
# 4) by forming a string on the S-slice S4,S4 = "2ab"
# 5) by forming a string on the S-Slice s5,s5 = "C"
# 6) by forming a string on the S-slice S6,S6 = "Ba2"
# s = "123a4b5c"
# print (S[0:3])
# print (S[3:6])
# print (S[::2])
# print (S[1:7:2])
# print (S[5::-2])
# 3. Make?while and for loop print characters # s= "Asdfer"
# for I in S:
# print (i)
# count = 0
# s= "Asdfer"
# while Count <len (s):
# print (s[c Ount])
# count+=1
# 5. Loop s = "ABCDEFG"
# with A For loop, each time the content is printed with SB, for example: ASB, BSB,CSB,... GSB.
# s = "ABCDEFG"
# for I in S:
# print (i+ ' SB ')
# 6. Make ?for loop to S = "321" into line cycle, the content of the printing sequence is: "Countdown 3 Seconds", "Countdown 2 Seconds", "Countdown 1 Seconds", "Go!" "。

# s = "321"
# for I in S:
# print ("Countdown {} seconds". Format (i))
# Else:
# print ("departure")

Python14 period (2018.7.4)

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.