首页 > 学院 > 开发设计 > 正文

9.11前9习题

2019-11-14 17:01:01
字体:
来源:转载
供稿:网友

 

1.PRint 

(1)打印的第一句 。。。。

1 print " Hello World! "

 

注意""和''的使用

1 print "i'm paul"   #2 3 print 'i'm paul'  # 错   改为 'i /'m paul'

以及""" """和''' '''的使用

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

 

(2)逗号

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

 

结果:

hello world abc

i am paul

 

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

结果:

hello world abc

 

i am paul

 

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

结果:

hello world abci am paul

 

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

语法错误

 

(3)运算符号

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

结果:

now i will count the eggs:

1

True

 

(4)变量及打印

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 70inches 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

结果:
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

结果:
ab ab ab ab ab ab ab ab ab 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 

结果:

a

b

c

 


上一篇:9.129-26节

下一篇:python与编码

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表