Blogger Information
Blog 32
fans 0
comment 0
visits 19619
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
python 习题 20-30
XuanGG的博客
Original
552 people have browsed it

# 习题 20 -30

# test 21
#else 意为else if 含义就是 否则如果 条件满足 就做yyy elif 后面需要有一个逻辑判断语句
'''
a =2 ;
if a ==1 :
   print 1
elif a ==2 :
   print 2
elif a ==3 :
   print 3
else:
   print 'null'
'''

# test 22 if 的嵌套 和for 循环一样 if 也可议案套使用,即在一个if/elif/else内部,在使用if.
#这有点类似于电路的串联
'''
a =10
b =-3
if a <0:
   print 1
else:
   print 2
   if b <0:
       print 44
   else:
       print 55
'''

# test 23 list 中文可以翻译成列表,是用来处理一组有序的数据结构
'''
a =range(10)
b =[]
for i in a :

  b.append(i)

print b
'''
#test 24  list切片 list切片(slice)是在[]内提供一对可选数字,
#用:(英文冒号隔开冒号前数表示切片的开始位置,冒泡后的位置表示切片带哪结束技术从0开始
'''
l = [365, 'everyday', 0.618, True]
print l[:3]
print l[1:3]
print l[1:]
'''

# test26 字符串的分割 split()会按照指定分隔符分割
#分割后每一个字符串的是一个新的字符串,最终返回这些字符串的list
'''
a = "hello world"
b =a.split()
print b
print b[0]
'''
#test 27 join是字符串对象的一个方法作用一个list中所有字符串连接车工一个字符串
'''
s =';'
li = ['apple','pear','oranage']
fruit = s.join(li)
print fruit
print ''.join(['hello','world'])
'''

#test 28 字符串的索引和切片 字符串的一些与list相似的操作:遍历、索引访问、切片、连接字符。
'''
a = 'helloworld'
for i in a :
   print i,
print ','.join(i),
'''
'''
# test29 break 强行跳出循环 break
a =2
b =10
while a :
   b = b -1
   print a,b
   if b <0:
       break
'''
# test30
'''
scores = [10,20,30,40,60]
for i in scores:
   if i ==30:
       continue
 
   print i
'''

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!