0
点赞
收藏
分享

微信扫一扫

快速入门2


字符串

#感觉''与""区别不大嘛
testStr='Python'
isCool="is cool!"
print testStr[0]
print testStr[1:3]
print isCool[:2]
print isCool[0:]
print testStr[-2]
print testStr+" "+isCool
print testStr*2#print testStr/2 will throw exception
print '+'*20
helloWorld = '''hello
    world '''
print helloWorld

P
yt
is
is cool!
o
Python is cool!
PythonPython
++++++++++++++++++++
hello
    world



if,else,elif


x=9
print "abc"
if x>=10:
    print x
elif x<10:
    print x-2
else:
    print "..."

abc
7



for:


#stupid IDLE,can't input chinese,so i have to write english annotate
arr=['a',2,'3']
print arr

for a in arr:
    print a

for b in ['a','b','c']:
    print b,#, means not \n??
print#equals \n

for randomNum in range(8,10):#for(int i=0;i<10;i++)print i...
    print randomNum,
print '\n'

str='abcd'
for index,s in enumerate(str):
    print "%d" %index,s
print

['a', 2, '3']
a
2
3
a b c
8 9 

0 a
1 b
2 c
3 d

举报

相关推荐

0 条评论