1. 运算符
算数运算符

+ - * /

int / float :数字类型

# print(10 + 3.1)
# print(10 / 3)
# print(10 // 3)
# print(10 % 3)
# print(10 ** 2)

赋值运算符

增量赋值

age=18

age=age+1

print=(age) #19

age+=1

print(gae)#19

交叉赋值

x=18  y=22

x,y=22,18

print(x,y) # 22,18

链式赋值

x=y=z=10

print(x,y,z) #10,10,10

解压赋值

列表的解压赋值

# salaries=[1.1,2.2,3.3,4.4,5.5]
# a,b,_,_,_=salaries
# a,b,*_=salaries
# *_,a,b=salaries
# a,*_,b=salaries
# print(a,b,) 2. 字典的解压赋值
 dic={'aaa':1,'bbb':2,'ccc':3}
# x,y,z=dic
# print(x,y,z)

逻辑运算符

and or not

# and: 左右两个条件必须同时成立,最终结果才为True
# print(10 < 3 and 3 == 3) # or: 左右两个条件只要有一个成立,最终结果就为True
# print(10 < 3 or 3 == 3)
# print(10 < 3 or 3 < 3) # not:将紧跟其后的条件结果取反
# print(not 10 > 3)
# print(not 10 < 3 or 3 < 3) # res=(10 > 3 and 3 == 1) or ((4 < 3 and True) or (not 1 > 2 or 3 > 2)) # print(res)

比较运算符

# ==
# print(10 != 3) # 了解
# msg1='abcdef'
# msg2='abcz' # print(msg2 > msg1) l1=[1,'aaa',333]
l2=[2,'b']
print(l2 > l1)

2. 流程控制
if

语法一:
# if 条件:
# 代码1
# 代码2
# 代码3 # gender='female'
# age=18
# is_beautiful=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
# print('开始表白。。。。')
#
# print('其他代码') #语法二:
# if 条件:
# 代码1
# 代码2
# 代码3
# else:
# 代码1
# 代码2
# 代码3 # gender='female'
# age=26
# is_beautiful=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
# print('开始表白。。。。')
# else:
# print('阿姨好')
#
# print('其他代码') #语法三:
# if 条件1:
# if 条件2:
# 代码1
# 代码2
# 代码3 # gender='female'
# age=18
# is_beautiful=True
# is_successfull=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
# print('开始表白。。。。')
# if is_successfull:
# print('在一起,,,')
# else:
# print('逗你玩呢。。。')
# else:
# print('阿姨好')
#
# print('其他代码')
# #语法四:
# if 条件1:
# 代码1
# 代码2
# 代码3
# elif 条件2:
# 代码1
# 代码2
# 代码3
# elif 条件3:
# 代码1
# 代码2
# 代码3
# .......
# else:
# 代码1
# 代码2
# 代码3 '''
如果:成绩>=90,那么:优秀 如果成绩>=80且<90,那么:良好 如果成绩>=70且<80,那么:普通 其他情况:很差
''' score=input('your score: ')
score=int(score) if score >= 90:
print('优秀')
elif score >= 80:
print('良好')
elif score >= 70:
print('普通')
else:
print('很差')

循环(while/for)

 引入:
# name='egon'
# pwd='123'
#
# inp_name=input('your name: ')
# inp_pwd=input('your password: ')
# if inp_name == name and inp_pwd == pwd:
# print('login successfull')
# else:
# print('name or password error')
#
# inp_name=input('your name: ')
# inp_pwd=input('your password: ')
# if inp_name == name and inp_pwd == pwd:
# print('login successfull')
# else:
# print('name or password error')
#
# inp_name=input('your name: ')
# inp_pwd=input('your password: ')
# if inp_name == name and inp_pwd == pwd:
# print('login successfull')
# else:
# print('name or password error')
#
#循环就是重复做某件事
# 语法:
# while 条件:
# 代码1
# 代码2
# 代码3 # while True:
# 1+1 # n=1
# while n < 10:
# print(n)
# n+=1 # name='egon'
# pwd='123'
#
# tag=True
# while tag:
# inp_name=input('your name: ')
# inp_pwd=input('your password: ')
# if inp_name == name and inp_pwd == pwd:
# print('login successfull')
# tag=False
# else:
# print('name or password error') # while+break:终止本层循环
name='egon'
pwd='123' while True:
inp_name=input('your name: ')
inp_pwd=input('your password: ')
if inp_name == name and inp_pwd == pwd:
print('login successfull')
break
else:
print('name or password error')
 
 

day04 运算符 流程控制 (if while/of)的更多相关文章

  1. python的学习笔记01_3 基本运算符 流程控制if while 字符串常用办法

    基本运算符 运算符 计算机可以进行的运算有很多种,可不只加减乘除这么简单,运算按种类可分为算数运算.比较运算.逻辑运算.赋值运算.成员运算.身份运算.位运算,今天我们暂只学习算数运算.比较运算.逻辑运 ...

  2. <基础> PHP 运算符 流程控制

    PHP运算符优先级: 递增/递减 (++ / --) > 算术运算符(+ .- .* ./) > 大小比较 > 逻辑与 (&)> 逻辑或(||) > 三目 > ...

  3. python - 用户交互/数据类型/格式化输出/运算符/流程控制单双多分支

    python:用户交互: 等用户输入,做反应: username=input("username:")password=input("password:")pr ...

  4. day52类型转换 运算符 流程控制

    0.复习 1.导入 <div id="div1" onclick="this.style.color = 'red';">12345</div ...

  5. DAY04、流程控制if、while、for

    一.if 判断 语法一: if 条件: # 以下是上一条if 的子代码块 print(子代码1) print(子代码2) print(子代码3) 示例: # 路边飘过一个生物,要不要表白? sex = ...

  6. day04之流程控制

    if语句: if 条件1: pass elif 条件2: pass elif 条件3: pass else: pass if 条件语句中,先判断条件1,如果满足条件1,则执行第二行代码,第二行执行完后 ...

  7. JAVA:变量,数据类型,运算符,流程控制(简介)<1>

    一.安装和配置jdk 1.jdk是什么? (1).jdk全称是Java Development Kit, Java开发工具包; (2).jdk是sun公司开发的; (3).jdk主要包括:jre(Ja ...

  8. Java学习第一篇:变量,数据类型,运算符,流程控制(简介)

    一.安装和配置jdk 1.jdk是什么? (1).jdk全称是Java Development Kit, Java开发工具包; (2).jdk是sun公司开发的; (3).jdk主要包括:jre(Ja ...

  9. java基础语法2-运算符与流程控制

    关键字-标识符-常量和变量-运算符-流程控制-方法-数组 5 运算符 算术运算符Arithmetic Operators 赋值运算符Assignment Operators 比较运算符Compare ...

随机推荐

  1. CDH安装报错 Monitor-HostMonitor throttling_logger ERROR ntpq: ntpq -np: not synchronized to any server

    1 没有安装ntp同步服务 所有机器统一时区,确认所有机器配置一致  vim /etc/sysconfig/clock ntp服务器配置 ln -sf /usr/share/zoneinfo/Asia ...

  2. Python之 string 和 random方法

    1. import string import string print(string.ascii_lowercase) #输出全部小写字母a-z print(string.ascii_letters ...

  3. 使用Protobuf定义网络协议

    准备工具: 工具下载地址如下:https://github.com/protocolbuffers/protobuf/releases/tag/v3.6.1,主要使用到的文件有: protoc.exe ...

  4. Centos 04 基础系统优化命令

    在Linux这个系统当中,几乎所有的硬件设备文件都在/dev这个目录内.举例来说,IDE介面的硬盘的文件名称即为/dev/hd[a-d],其中, 括号内的字母为a-d当中的任意一个,亦即有/dev/h ...

  5. 🌵react小记 🌵

  6. 列式数据库~clickhouse问题汇总

    一 简介:常见的clickhouse 问题汇总 二 问题系列  1 内存问题     Code: 241. DB::Exception: Received from localhost:9000, : ...

  7. JSP表达式语音EF--2

    JSP 表达式语言 | 菜鸟教程 http://www.runoob.com/jsp/jsp-expression-language.html

  8. linux(ubuntu) python 版本切换

    参考链接:https://blog.csdn.net/thankyou0/article/details/79610854

  9. POJ 1458 Common Subsequence 最长公共子序列

    题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...

  10. Solr创建Core的两种方法

    创建Core的两种方法: 第一种方法: 1.打开dos命令窗口,切换目录到${solr.home}\bin,然后输入:solr create -c corename之后回车: 2.打开solr安装文件 ...