def trim(s):
while s[:1] == ' ':
s = s[1:]
while s[-1:] == ' ':
s = s[:-1]
return s
str = ' facesoho '
print(trim(str))
908Python While 循环语句
while循环 - 九九乘法表
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#九九乘法表
i = 1
while i :
j = 1
while j:
print j ,"*", i ," = " , i * j , ' ',
if i == j :
break
j += 1
if j >= 10:
break
print "\n"
i += 1
if i >= 10:
break
911Python for 循环语句
for 使用案例
使用list.append()模块对质数进行输出。
输出结果:
910Python for 循环语句
使用内置 enumerate 函数进行遍历:
实例
909Python While 循环语句
Pyhton 去除字符串首尾的空格:
908Python While 循环语句
while循环 - 九九乘法表
907Python While 循环语句
十进制转二进制