First give us a dry ^~^, learn a good Python site, http://learnpythonthehardway.org/book/
Classic examples
Here are a few examples of old classics, just contact Python to knock and see the results!
My_name= ' Zed A. Shaw ' My_age=35#not a liemy_height=74#inchesmy_weight=180#1bsmy_eyes= ' Blue ' my_teeth= ' white ' my_hair= ' Brown ' Print My_nameprint "Let's talk about%r"%my_nameprint "he ' s%d inches tall."%my_heightprint "He's%d pounds heavy . "%my_weightprint" actually that's not too heavy. " Print "He ' s got%s eyes and%s hair."% ( My_eyes,my_hair) print "his teeth is usually%s depending on the coffee." %my_teeth#this Line was tricky,try to get it exactly rightprint "If I add%d,%d,and%r I get%d."% ( My_age,my_height,my_weight,my_age+my_height+my_weight)
X= "There is%d types of people." %10binary= "binary" do_not= "Don T" y= "those who know%s and those who%s"% (binary,do_not) print xprint Yprint "I said:%r." %xprint "I also said: '%s '." %yhilarious=falsejoke_evaluation= "Isn ' t that joke so funny?! %r "Print joke_evaluation% hilariousw=" This is the left side of ... "e=" a string with a right side "print W+e
Print "Mary had a little lamb." Print "Its fleece is white as%s." % ' Snow ' print "its fleece is white as%r." % ' Snow ' print "and everywhere that Mary went." Print "." *10 #output. Ten timesend1= "C" end2= "H" end3= "E" end4= "E" end5= "S" end6= "E" #watch that comma at the End.print end1+end2+end3,print end4+ End5+end6
Formatter= "%r%r%r%r" Print formatter% (1,2,3,4) print formatter% ("one", "one", "a", "three", "four") print formatter% (True, false,false,true) Print formatter% (formatter,formatter,formatter,formatter) print formatter% ("I had this thing.", " That's could type up right. "," but it didn ' t sing. "," so I said Goodnight. ")
days= "Mon Tue Wed Thu Fri Sat Sun" months= "Jan\nfeb\nmar\napr\nmay\njun\naug" print "Here is the days:", Daysprint "here is The months: "Monthsprint" Here is the months:%r "%months#that's how%r formatting works; #it prints it the wrote it (or close to it). It's the "raw" format for Debugging.print "" "There's something going on Here.whith the three double-quotes.we ' ll be able t o Type as much as we like. Even 4 lines if we want, or 5, or 6. ""
tabby_cat= "\ti ' m stabbed in." persian_cat= "I ' m Split\non a line." backslash_cat= "I ' m \ \ a \ \ Cat." Fat_fat= "" "I ll do a list:\t* Cat food\t* fishies\t* catnip\n\t* Grass" "Print Tabby_catprint persian_catprint backslash_ Catprint Fat_fat
The difference between%r and%s
My summary is this point: the difference between%r and%s
That's how%r formatting works; It prints it the IT-wrote it (or close to it). It ' s the ' raw ' format for debugging.
Always remember this: %r is for debugging, %s is for displaying.
One into Python deep like sea--print