python从0到1学习笔记

Python 逻辑运算,条件判断,循环等

2018-08-15  本文已影响13人  三不小青年

#or and not 逻辑运算符

a =1

b =2

print(a ==1 or b ==3)#true

print(a ==1 and b ==3)#false

print(a ==1 and not b ==3)#true

#if else 语句,表达式前面空下四个空格

ACCOUNT ="WuGuang"

CODE ="123456"

# user_account = input()

user_account ="WuGuang"

# user_code = input()

user_code ='12345'

if user_account == ACCOUNTand user_code == CODE:

print("你好")

else:

print("不好")

#elif 不用做过多的代码块缩进

a =1

b =2

if a ==1:

print('a==1')

elif b ==2:

print('b==2')

#三目运算符

a =3

b =4

print(aif (a > b)else b)

#For 循环

a = ['a''b''c''d' 'e' 'f' 'g']

for indexin range(0,len(a)):#根据下标取元素

    print(a[index])

for itemin a:#循环取元素

    print(item)

上一篇 下一篇

猜你喜欢

热点阅读