使用 for 循环遍历 Python 字典
# list 切片后仍是list
list=['a','b','c','d']
print(list[:2]) # ['a', 'b'] 结果为list
print(list[:1]) # ['a'] ▲结果仍为list
s='hello'
s1=''
for i in s:
if i=='e':
continue # 使用continue语句跳出当前循环迭代
s1 += i
print(s1)
print(1>2) # False
n=input()
n = int(n)
print(n>4 or n<4)
n,m = 2,3
if n<m:
n,m = m+2,n
print(n,m) # 5,2
# list 切片后仍是list
list=['a','b','c','d']
print(list[:2]) # ['a', 'b']
print(list[:1]) # ['a']
n=input()
m=input()
print(n+m) # n m 均为字符串,+ 作为字符串连接用
n=9
m=8
n = n*m-n # n = 8*9 -9 =63
m = n-5*m # m = 63 - 5*8
print(m) #23
n=10
m=20
if n==10 or m==40:
print('hello') # 输出 hello
else:
print('world')
n=6
print('n+1') # n+1
print(21/7==3 and 7) # 7
sum = 0
num = [1,8,0,4]
for i in num:
if i<5: # 跳过8
sum += i
print(sum) # 5
print(4**2-6/2) # 13.0
n=0
m = 0 or 1 # 1
print(n==m) # False
n=eval('6+8/2') #
print(n) #10.0
#eval是Python的一个内置函数,这个函数的作用是,返回传入字符串的表达式的结果
dic = {'name':'jack','age':15,'number':1804} for i in dic: # i 为字典键 print(i[:1]) # ame ge umber str = 'hello' str= str.split('e')[1][1] print(str) print('abc'>'ac')
使用 for 循环遍历 Python 字典 https://baijiahao.baidu.com/s?id=1713928110213127319&wfr=spider&for=pc