9.11 first 9 exercises, 9.119 exercises

Source: Internet
Author: User

9.11 first 9 exercises, 9.119 exercises

 

1. print

(1) print the first sentence ....

1 print " Hello World! "

 

Note the use of "" And''

1 print "I'm paul" # For 2 3 print 'I am paul' # the error is changed to 'I \'m paul'

And the use of "And '''

1 print  """2 3 Hello World!4 5 Hello World!6 7 Hello World!8 9 """

 

(2) comma

print "hello world ",'abc'print "i am paul "

 

Result:

Hello world abc

I am paul

 

print "hello world "  'abc'print "i am paul "

Result:

Hello world abc

 

I am paul

 

print "hello world" ' abc',print "i am paul"

Result:

Hello world abci am paul

 

print "hello world" ' abc',"i am paul"

Syntax Error

 

(3) operator number

print "now i will count the eggs:"print 3+1+2-5+4%2-1/4print 3+2>4-2

Result:

Now I will count the eggs:

1

True

 

(4) variables and Printing

name = "paul"age = 20height = 70print "let's talk about %s"%nameprint "he's %d years old"%ageprint "he's %d inches tall"%heightprint "let's talk about %r"%nameprint "he's %r years old"%ageprint "he's %r inches tall"%height

print "if i add %d and %d,i get %d."%(age,height,age+height)

Let's talk about paul

He's 20 years old

He's 70 inches tall

Let's talk about "paul"

He's 20 years old

He's 70 inches tall

If I add 20 and 70, I get 90

 

x = "there are %d types of people."%10print x print "i said :%r "%xy =  "isn't that joke so funny? %r"z = Falseprint y%za = "this is the left of"b = "a string with a right side"print a + b

Result:
There are 10 types of people.

I said: there are 10 types of people.

Isn' t that joke so funny? False

This is the left of a string with a right side

 

print "ab " *10

Result:
AB

formatter = "%r %r %r"print formatter %(1,2,3)print formatter %("one","two","three")print formatter %(True,False,True)print formatter %(   "i had this string",   "that you could ",   "type  up right"       )

1 2 3
'One' two' 'three'

True False True

'I had this string ''that you could ''type up right'

 

1 a = "a\nb\nc\n"2 print a 

Result:

A

B

C

 

Related Article

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.