python 启航

first = 1
while first<=9:

    sec = 1   
    while sec <= first:
        print(  str(sec)+"*"+ str(first) +"="+str(sec * first), end=" ")
        sec += 1    
    print()
    first += 1

乘法表 内含while内嵌,str的+操作, 制表符的使用和print("***",end="$$$")的使用

print("***")时默认为print("***",end=" ")

while True:
    user_input_age = int(input("Age is :"))
    if user_input_age == age:
        print("Yes")
        break
    elif user_input_age > age:
        print("Is bigger")
    else:
        print("Is smaller")   
print("End")

while 嵌套 if 语句,包含if, else,break 的使用,与c语言语法一样

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

while else 语句else后的语句当while正常结束时执行,也就是非break终止时执行。

python中运算符的优先级与c语言相似,常用的运算符

**幂运算符------+ - ~按位取反和符号运算符(+-表示正负号)-------* / // %(乘除整除和取余)------+ -(加减)--------<<  >>(移位运算符)--------&  |  ^(位运算符)--------

>  <  ==  !=(关系运算符)-------+= -= *= /= **=(赋值运算符)--------and or not (逻辑运算符) 其中and >or ,not为单目运算符,与and or双目运算符无比较。

>>> False and True or True
True
>>> True or True and False
True
>>>

从上可以看出

变量 : 存储信息的,日后被调用、修改操作
常量: 固定不变的量,字母大写
命名规则:
1. 字母数字下划线组成
2. 不能以数字开头,不能含有特殊字符和空格
3. 不能以保留字命名
4. 不能以中文命名
5. 定义的变量名应该有意义
6. 驼峰式命、 下划线分割单词
7. 变量名区分大小写

# 单行注释
'''多行注释'''
""" 多行注释 """除此之外

”“”  ###

¥¥¥

$$$

“”“”

可以用于编辑多行文字

#coding:utf-8可用于修改编码方式

原文地址:https://www.cnblogs.com/MY0213/p/7660458.html