1. Loop statements

"""While condition: Code block"""

# while 1>0:
#     print("To"CTRL + left click print to view the native API print("Wang", end=""# cancel print default newline print("Old zhang")

import random
num = random.randint(1.100)
# while True:
#     inum = int(input("Enter a number"))
#     if inum < num:
#         print("Little guess.")
#     elif inum > num:
#         print("Big guess.")
#     else:
#         print("Got it right.") # # break the loopcontinueJump out of the loop and proceed to the next loop #break

name = 'laowang'
for i in name:
    print(i)

for i in range(1.10) : #1= >9
    print(i)

for i in range(1.10.2): # third parameter step size1 3 5 7 9Print (I) #for i in range(1.10) :for j in range(1,i+1):
        print({} * {} = {}".format(j,i,i*j),end="")
    print(' ')

Copy the code

2.列表 append(”) , insert(1,”), extend  ,  reomve ,reverse== [::-1], sort,  sorted,len,count

# list classes = [] # append()'Joe')
classes.append('bill')
classes.append('Cathy'# insert add classes.insert()0.Dee Renjie# extend add classes.extend()"Da ji"Print (classes) # delete classes."Zhang"Pop () classes.pop() classes.pop()0) print(classes) # change classes[1] = "Cao four"Print (classes) # name = classes[1Print (name) print(name)2.0.3.51.23.867.32.75.175[::-] [::-] [::-] [::-1Print (l) l = sorted(l, l) l = sorted(l, l) Reverse =True print(l) print(l1) print(l2)1:3] # subscript1 2 [1.3)
print(l2)

l3 = l[1:4:2# # # # # #1.4) 1.3Is step [0.51Print (len(l)) print(l)2))  # 2There's a # in the L2Check if the element is in the list2 in l)  # True
print(2 not inL) # False # calculate1-100List = []for i in range(2.101):
    flag = True
    # print(i, ' ', end=' ')
    for j in range(2, i):
        # print(j,' ', end=' ')
        if (i % j == 0):
            flag = False
            break
    ifFlag: list.append(I) print(list) #1.1.2.2.2.3.3.54.7.3.6.9.43.76]
tmp = []
for i in list2:
    if(i not in tmp):
        tmp.append(i)
print(tmp)
Copy the code