Test your Python level----7

Source: Internet
Author: User

1. Q: What is the difference between Cpython,jython and IronPython?
A: All three are the implementation of the Python compiler, CPython is the standard implementation of Python, Jypthon is the Java implementation of Python, IronPython is a python. NET implementation.

2. Q: What is the purpose of exec,eval,execfile?
A: 1) EXEC executes the python statement stored in the string, such as exec ("print ' Hello world! '");
2) eval evaluates the stored string as an expression, such as eval ("1+2+3+4+5+6");
3) execfile is used to execute a file script, such as execfile ("test.py");

3, Q: How to view all the properties of a module?
Answer: Dir (modulename)
The Ps:dir function is really a great invention in Python that gets the properties of the module through its reflection;

4. Q: Please use Python to get the contents of the http://www.freelycode.com (free Code) homepage.
A: The use of Urllib module implementation;
Import Urllib
def gethtml (URL):
page = Urllib.urlopen (URL)
html = Page.read ()
return HTML

html = gethtml ("http://www.freelycode.com")
Print HTML


5. (5 python questions per day (6)) readers have proposed the last fifth interception of text more than 80 characters lines, the implementation of the program to be considered thoughtful, mainly:
1) does not take into account a line greater than 160 characters
2) The stitching problem of the interception line,
The author has re-perfected the procedure as follows:
Import OS

Fpout=open (' Test.txt ', ' R ')
Fpin=open (' Test1.txt ', ' W ')

Left= ""
For line in Fpout:

#先拼接

Line=left+line


Leng=len (line)

if Len (line) >80:

count=leng/80

for I in Range (count):

for I in Range (80,0,-1):

#从最接近80的单词截取

if line[i].isspace ():

fpin.write (line[0:i]+ ' \ n ')

Line=line[i+1:]

Break

#处理剩余行用于拼接

left=line.replace ("\ n", "")

Else

Fpin.write (line)


Test your Python level----7

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.