python基础学习2

一.算数运算符

+加法,-减法,*乘法,/除法,//地板除,%求余,**幂运算。

二.逻辑运算符

非not、且and、或or。优先级依次为not,and,or。

三.print()end结尾

print()#默认为print(end="
"),想要输出在一行可写为print(end="")

四.while循环

num = 1
while num<10: 
    print(num)  
    num+=1 

  break为终止当前循环体,continue为结束当次循环。

age=30
while True:
    input_age = int(input("Age is :"))
    if input_age == age:
        print("It's right.")
        break
    elif input_age > age:
        print("It's bigger.")
    else:
        print("It's smaller.")       
print("End")

五.while和else的配套使用

num = 1
while num <= 5:
    num += 1   
    print(num)
else:
    print("This is else statement")

如果使用break,那么else也不会执行。

六.while的嵌套使用--输出九九乘法表

row = 1
while row<=9:
    col = 1    
    while col <= row:
        print(  str(col)+"*"+ str(row) +"="+str(col * row), end="	")
        col += 1        
    print()    
    row += 1
    

  

  

原文地址:https://www.cnblogs.com/sfencs-hcy/p/9505348.html