python

and运算符就是所谓的布尔运算符,连接两个布尔值,并且在两者都为真时返回真,否则 返回假,or not 可以随意结合真值

短路逻辑 short-circuit logic   惰性求值 lazy evaluation
raw_input 返回值为真
断言,条件后可以添加字符串,用来解释断言

x = 1
Yes = input('Are you readly?')
if Yes.lower() == 'yes':
    while x <= 'yes':
        print(x)
        x += 1

缩进对Python 太重要了!

name = ''
while not name:
    name = input('Please enter your name: ')
print('Hello,%s!' % name)

Name = input('Please input you name: ')
name = Name
while not name or name.isspace():
    #while not name.strip() or while not name or name.isspace()
    #
    name = input('Please enter your name: ')
print('Hello,%s!'% name)

# sequence list   words = ['this','is','an','ex','parrot']
#for word in words:
#    print(word)
"""
numbers = [0,1,2,3,4,5,6,7,8,9]
for number in numbers:
    print(number)
"""
'''
d = {'x':1,'y':2,'z':3}
for key in d:
    print(key,'corresponds to',d[key])
#multiline commit  for python
#one line commeit for Python
'''
'''
d = {'x':1,'y':2,'z':3}
print(d[key])

#for key in d:
#    print(d[value])

'''
'''
d = {'x':1,'y':2,'z':3}
for key,value in d.items():
    print(key,'correspond to',value)
    

'''
"""
names = ['anne','beth','george','damon']
ages = [12,45,32,102]
for i in range(len(names)):
    print(names[i],'is',ages[i],'years old')


for string in strings:
    if 'xxx' in string:
        index = strings.index(string) # Search for the string in the list of strings
        strings[index] = '[censored]'
"""

for string in srings:
    if 'xxx' in string:
        index = strings.index(string)
        strings[index] = '[censored]'

原文地址:https://www.cnblogs.com/ruiy/p/5083403.html