pythontop函数 python中plt函数( 四 )


else:
print "3 - 变量 a 和 b 有一个不为 true"
if ( a or b ):
print "4 - 变量 a 和 b 都为 true,或其中一个变量为 true"
else:
print "4 - 变量 a 和 b 都不为 true"
if not( a and b ):
print "5 - 变量 a 和 b 都为 false,或其中一个变量为 false"
else:
print "5 - 变量 a 和 b 都为 true"
in,not in
a = 10
b = 20
list = [1, 2, 3, 4, 5 ];
if ( a in list ):
print "1 - 变量 a 在给定的列表中 list 中"
else:
print "1 - 变量 a 不在给定的列表中 list 中"
if ( b not in list ):
print "2 - 变量 b 不在给定的列表中 list 中"
else:
print "2 - 变量 b 在给定的列表中 list 中"
a = 2
if ( a in list ):
print "3 - 变量 a 在给定的列表中 list 中"
else:
print "3 - 变量 a 不在给定的列表中 list 中"
条件
flag = False
name = 'luren'
if name == 'python':# 判断变量否为'python'
flag = True# 条件成立时设置标志为真
print 'welcome boss'# 并输出欢迎信息
else:
print name
num = 5
if num == 3:# 判断num的值
print 'boss'
elif num == 2:
print 'user'
elif num == 1:
print 'worker'
elif num0:# 值小于零时输出
print 'error'
else:
print 'roadman'# 条件均不成立时输出
循环语句:
count = 0
while (count9):
print 'The count is:', count
count = count + 1
print "Good bye!"
i = 1
while i10:
i += 1
if i%20:# 非双数时跳过输出
continue
print i# 输出双数2、4、6、8、10
i = 1
while 1:# 循环条件为1必定成立
print i# 输出1~10
i += 1
if i10:# 当i大于10时跳出循环
break
for letter in 'Python':# 第一个实例
print '当前字母 :', letter
fruits = ['banana', 'apple','mango']
for fruit in fruits:# 第二个实例
print '当前水果 :', fruit
print "Good bye!"
获取用户输入:raw_input
var = 1
while var == 1 :# 该条件永远为true,循环将无限执行下去
num = raw_input("Enter a number:")
print "You entered: ", num
print "Good bye!"
range,len
fruits = ['banana', 'apple','mango']
for index in range(len(fruits)):
print '当前水果 :', fruits[index]
print "Good bye!"
python数学函数:
abs,cell,cmp,exp,fabs,floor,log,log10,max,min,mod,pow,round,sqrt
randrange
访问字符串的值
var1 = 'Hello World!'
var2 = "Python Runoob"
print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]
转义字符
格式化输出
print "My name is %s and weight is %d kg!" % ('Zara', 21)
字符串函数:
添加元素
list = []## 空列表
list.append('Google')## 使用 append() 添加元素
【pythontop函数 python中plt函数】list.append('Runoob')
print list
删除元素
list1 = ['physics', 'chemistry', 1997, 2000]
print list1
del list1[2]
print "After deleting value at index 2 : "
print list1
列表操作
列表方法
删除字典
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'};
del dict['Name']; # 删除键是'Name'的条目
dict.clear();# 清空词典所有条目
del dict ;# 删除词典
print "dict['Age']: ", dict['Age'];
print "dict['School']: ", dict['School'];
字典的函数:
当前时间戳:
import time
time.time()
格式化日期输出
import time
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())
a = "Sat Mar 28 22:24:24 2016"

推荐阅读