二、Python3 变量、运算、表达式

一、变量

A = [1,2,3,4,5,6]
print(A * 3)
isinstance(1, int)
isinstance('1', str)
isinstance('1', (str,int,list))

二、运算符

1、算术运算符:
加、减、乘、除、整除、余数、平方、6次方

+、=、*、/、//、%、**2、**6

2、赋值运算符:

=、+=、*=、/=、**=、//=

b = b + a
b += a
b = b * a
b *= a

3、关系运算符:

==、!=、>、<、>=、<=

4、逻辑运算符:

and、or、not

True and False

5、成员运算符:

in、not in

1 in [1,2,3]
'h' in 'hello'
1 in {'a' : 1}

6、身份运算符:

is、is not

is比较的内存地址、==比较的是值

1 is 2
'hello' is 'hello'

7、位运算符:

|、~、<<、>>、&、^

三、表达式

1、表达式的优先级
在这里插入图片描述

2、条件控制语句:if、elif、else

print('Please input Number')
aaa = input()
if aaa > 10 :
    print ('> 10')
elif aaa >  4:
    print ('> 4')
else:
    print ('Others')
if 12 > 10:
    pass #占位

3、循环控制语句:while、for

count = 1
while count < 20:
    print (str(count) + '< 20')
    count+=1
else:
    print (str(count) + 'out')
countList = [0,1,2,3,4,5,6,7,8,9,10]
for i in countList:
    print (i)
    if i==6:
        break #continue
else:
    print ('out')
for i in range(0,100,9):
    print (i)
countList = [0,1,2,3,4,5,6,7,8,9,10]
for index,value in enumerate(countList):
    if value==6:
        continue
    print (value)
else:
    print ('out')
countList = {'aa':'aa','bb':'bb'}
for key, value in countList.items():
    print (key,'=',value)
else:
    print ('out')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值