Discover learn python hard way exercise 0, include the articles, news, trends, analysis and practical advice about learn python hard way exercise 0 on alibabacloud.com
Some extensions are made according to the content of chapter 16.For example, if a file exists, it is appended to the file and created if it does not exist.It also draws on a method similar to the cat Now there is a small pit, how to use Python to read a file of the number of rows, the original Os.system ("Wc-l filename") is OK, but how to operate under Windows? Fill it back.#!/usr/bin/env python#-*-coding:u
How to open a file in cmd : First open the cmd interface with Win+r , after the address known to you to open the file, such as (f:\ Workspace), you press F:and then you enter workspace with the CD workspace File , and then put in the file you want to open (the name + file type), and then you can open the file. in the in Python, the function of entering characters is:input(which can be any character), and the characters in parentheses are printed .The
the same, for example, to deal with an int type Object%r will be more "on the side of the string."String (srring) and textW = "This is the left side of ..." E = "a string with a right side." Print W + ethis is the left side of...a string with a right Side.print "." * 10 .....Printdays= "Montuewedthufrisatsun" months= "Jan\nfeb \nmar\napr\nmay\njun\njul\naug "print" herearethedays: ",days print "herearethemonths:",monthsprint "" "There ' s Somethinggoingonhere.withthethreedouble-quotes.we ' Llbe
print" We have it girls with%d. The number of "% nv_countprint" IT staff: >>> Nan_nad_nv (60,20) Results The number of IT staff is: we have 60 of it boys. We have 20 of it girls.19. Functions and variablesdef cheese_and_crackers (Cheese_count, boxes_of_crackers): print "You had%d cheeses!"% cheese_count print "you h Ave%d boxes of crackers! "% boxes_of_crackerscheese_and_crackers (20, 30) results you have a total of cheeses! You have a boxes of Crackers!amount_of_cheese = Amount_of_crackers = C
This section describes the integrated operation of functions and files.were carried out separately. 1, read out all the contents of the file, 2, reset the file to the beginning of the file. 3, print a line.I made a small improvement in this section, set up a global variable, record which line should be entered at the moment, and if so, I'll add one to the number.The code section is as follows:#!/usr/bin/env python#-*-coding:utf-8-*- fromSysImportArgvs
to query (enter Q exit):" ") Company="'#pre-defined units whileCompany! ='Q': Department=input ()ifDepartment = ='Q': Break elif notDepartmentinchDic_of_ncepu:Print('The system is not queried, please re-enter') Continue Else: ifLen (dic_of_ncepu[department]) = = 1: Print(Dic_of_ncepu[department])Else: Print('Please enter the subordinate units of the department you are inquiring about: (press B to return, press Q to exit)') whileTrue
are like importedIf the class is like a module, then there should also be an import-like concept. In a class, this concept is called instantiation, and when a class is instantiated, it gets the object of a class.Create a class;Class MyStuff (object):def __init__ (self):SELF.A = ' How is it? 'def apple (self):Print ("I am classy apple")b = MyStuff () #类的实例化B.apple () #调用类的方法Print b.a# properties of the printing classAnalyzing the instantiation of a class this sentence actually
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.