Home > other >  Print (* G1) how to understand
Print (* G1) how to understand

Time:10-25

 
Def gen () :
For n in the range (12) :
The yield of n * * 2

G1=(n * * 2 for n in the range (12))
G2=gen ()
Print (* G1)
Print (" * "G2")
Print (list (G1))
Print (list (G2))

# output:
# 0 1 4 September 16 to 25 36 49 64 81 100 121
# 0 1 4 September 16 to 25 36 49 64 81 100 121
# []
# []



CodePudding user response:

* can be used to collect and distribute parameters, G1 is a generator objects, * G1 can take all of these parameters extracted, assigned to the print (),

CodePudding user response:

You when it is a method with pick up address, no need to worry about the specific implementation, are vector generation characteristics can be used

CodePudding user response:


 
These types with iterative properties, # that is not only the iteration time!
Def gen () :
For n in the range (12) :
The yield of n * * 2

G1=(n * * 2 for n in the range (12))
G2=gen ()

Print (* G1)
Print (" * "G2")
Print (list (G1))
Print (list (G2))
For I in G1:
Print (I)
For j in G2:
Print (j)


Print (* G1)
Print (" * "G2")
Print (list (G1))
Print (list (G2))
For I in G1:
Print (I)
For j in G2:
Print (j)



# output:
# 0 1 4 September 16 to 25 36 49 64 81 100 121
# 0 1 4 September 16 to 25 36 49 64 81 100 121
# []
# []


# []
# []
  • Related