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

Python 习题 11-20


# test 11 字符串  字符串就是一组字符的序列,最常用的表式方法是英文引号包围的字符

#print '我是一个字符串'
#print "我也是"

# test12  字符串格式化 : 通过 % 操作符。可将一些数值插入到字符串中间 拼接出指定的字符串
'''
a = '古天乐'
b = '渣渣辉'
c = 18
d = True
print '大家好我是 %s' % a
print '我是 %s ' % b
print '我们 %d' % c
print '我的价格是%.2f' % 4.601
'''
# test13  将两个及以上的循环,叠加在一起使用
'''
for i in range(3):
   for j in range(3):
       print '*',
   print '@',
'''
# test14 字符串格式化2 通过元组实现多个值的格式化
'''
a ='xiaoxuan'
b =18
print 'my name is %s and my age is %d' % (a,b)
'''

# test15 类型转化 python 的变量会根据赋值自动决定它的类型。也可以通过一些方法改变一个变量的类型
'''
a = '18'
b =int(a)

print  type(a)  # 类型为 str
print  type(b)  # 类型为 int  
'''

# test 16 bool 类型转化 在python中,0,空字符串、None 空集合会被认为是False ,其它的值的认为是True
'''
a =''
b ='None'
c = []
d ='aa'
print bool(a)
print bool(b)
print bool(c)
print bool(d)

'''

# test 17 函数就是一块语句,这块语句有个名子,你可以在需要时反复的使用者快语句。它有可能会返回输出。
'''
def a(x,y):  # def 定义函数
   print x + y

a(1,2)
'''
# test 18

#如 17 所示


# test 19 函数返回值
'''
def num(a,b):
   if a > b :
       return True
   if a < b :
       return False
print num(1,2)

'''

# test20 else : 如果条件满足,就做xxx 否则就是不做。 else顾名思义。就是:'否则' 就做yyy
'''
a = 5
if a >10:
   print 'ok'
else:
   print 'NULL'
'''

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!