1) Determine two elements of the same list content
L1=[11,22,33]l2=[22,33,44]for i in L1: if I in L2: print (i)
2) get an element in L1 that is not in the L2
For i in L1: If I is not in L2: print (i)
From big to small print 1-100
Li=[]for i in range (1,101): li.append (i) Li.reverse () print (LI) for I in range: print (str (100-i) + ', '), for I In range (100,0,-1): print (i)
Calculates a list of two 1-9, which can be combined into a number of digits, 10 digits, different numbers
Count=0for i in range (1,9): for J in Range (1,9): If I!=j: count=count+1print (count)
99 Multiplication Table
For I in Range (1,10): string= "" for J in Range (1,i+1): string+=str (j) + "*" +str (i) + "=" +str (i*j) + "\ T" Print (String)
1*1=1 #第一排不变的是被乘数1
1*2=22*2=4 #第二排 Constant is the multiplier 2
1*3=32*3=63*3=9 #第三排不变的是被乘 Number 1 So I is used as a multiplier cycle, and j is changed with I.
1*4=42*4=83*4=124*4=16
1*5=52*5=103*5=154*5=205*5=25
1*6=62*6=123*6=184*6=245*6=306*6=36
1*7=72*7=143*7=214*7=285*7=356*7=427*7=49
1*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=64
1*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81
string concatenation
li=["Alex", "Eric", 123] #应为123不是字符串类型, so you must first convert to a string in the join, if the list is a string, directly with the join can be LI[2]=STR (li[2]) v= "_". Join (LI) Print (v)
Tu= ("Alex", "Eric", "QQQ") print (Len (TU)) #获取元组的长度print (tu[2]) print (tu[1:]) print (tu[1:90]) for i in Tu: # Prints each element in a tuple print (i) for I in Range (len): #打印元组中元素的索引值 Print (i) Use enumerate to output the tuple ordinal and element at the same time, you must keep up with the iterator object, 10 is the designation starting from 10 for the sequence number for i,j in enumerate (tu,10): print (I,J)
Find any two elements in the list to add an element equal to 9
Li=[]nums=[2,7,11,15,1,8,7]for i in nums: nums = [2, 7, one, 1, 8, 7] nums.remove (i) for J in Nums: if I+j==9: li.append ((i,j)) print (LI)
Beginner Python's Simple program (2)