1. Q: Briefly describe the relationship between Unicode and utf-8 in Python? What are the commonly used functions?
A: Unicode is a set of character encodings that define a unique encoding for each character; Utf-8 is an implementation of Unicode that uses variable-length encoding to store characters; commonly used functions:
1) Decode: implementation of conversion from other encodings to Unicode encoding
2) Encode: Enables conversion from Unicode to other encodings
2. The code snippet is as follows:
From Functools Import Partial
def mul (x,base): Return x*base
Mul10=partial (mul,base=10)
Mul100=partial (mul,100)
Q: Do the following four statements make an error? If there is no error, what is the output?
1) Print MUL10 (50)
2) Print Mul10 (50,base=100)
3) Print mul100 (50)
4) Print mul100 (50,base=100)
For:
1) 500
2) 5000
3) 5000
4) Report TypeError error, incoming multi-value
3. Q: Briefly describe the sequence of methods in Python multiple inheritance (method Resolution order)?
Answer:
1) Classic class: Depth first, left to right
2) New class: Breadth first, left to right
4, Q: List: a=[1,2,2,2,2,7,6,3,2,6,8,3,4,4,4,3,2,9,124,456,124,96,78,2,3,4,6,6,8,5], please find the number of duplicates in a.
For:
a=a=[1,2,2,2,2,7,6,3,2,6,8,3,4,4,4,3,2,9,124,456,124,96,78,2,3,4,6,6,8,5]
Seta=set (A)
For item in SetA:
If A.count (item) >1:
Print Item,
5. Write a program that requires a text line that is larger than 80 characters to break from the nearest 80 characters, insert the remaining text into the next line, and after the program ends, all lines in the text have fewer than 80 characters.
Fpout=open (' Test.txt ', ' R ')
Fpin=open (' Test1.txt ', ' W ')
For line in Fpout:
If Len (line) >80:
For I in Range (80,0,-1):
#查找最接近80的字符单词
If line[i]== ':
Break
#截取
Fpin.write (line[0:i]+ ' \ n ')
Fpin.write (line[i+1:])
Else
Fpin.write (line)
Fpout.close ()
Fpin.close ()
Test your Python level----6