9.11前9习题

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1.PRint

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

1print"Hello World!"

注意""和''的使用

1print"i'm paul"#对23print'i'm paul'#错 改为'i \'m paul'

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

1print"""23Hello World!45Hello World!67Hello World!89"""

(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:"print3+1+2-5+4%2-1/4print3+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."%10printxprint"i said :%r"%x

y="isn't that joke so funny? %r"z=Falseprinty%z

a="this is the left of"b="a string with a right side"printa + 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"printformatter %(1,2,3)printformatter %("one","two","three")printformatter %(True,False,True)printformatter %("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'

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

结果:

a

b

c

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航