python 基础1-变量名

变量名

1、组成:数字、字母、下划线

2、变量名要有意义

3、多个单词则用下划线,如user_id

4、python的变量名不要驼峰显示

字符串:

1、引号内的都称为 字符串

2、常用引号:' '," ",'' '',"" "",''' ''', """ """

3、支持运算:+,*

数值:

1、支持运算:+,-,*,/,**(指数),%(取余数),//(取商)

 如:3**4=81

         5%3=2

         5//3=1

if 条件语句

格式1:
if 条件:   print(“ok”) else:   print(“error”)

  

嵌套:
if 1 != 1:
    if 2 !=2:
        print("1")
    else:
        print("2")
else:
    print("---end---")

  

多次判定:
score = input("请输入你的分数:")
if score == '90':
    print("优秀")
elif score == "80":
    print("良好")
elif score == "70":
    print("一般")
elif score == "60":
    print("及格")
else:
print("不及格")

  

补充:pass 用法(成立则不执行)

输出1-100的奇数:
n = 0
while n <= 100:
    n+=1
    if n%2 == 0:
         pass
    else:
        print(n)
print("---end---")

循环:

死循环:

import time
while 1==1:
    print("ok",time.time())

  

猜你喜欢

转载自www.cnblogs.com/zhuanfang/p/12399041.html