Generating a sequence of 1 to 10, which is divisible by 3 positions replaced java, be divisible position 5 replaced python
Firstly, the code, then the code is understood:
Java, Python = ' java ' , ' python ' jl, pl = len (Java), smooth (python) print ([str (java [in% 3 * JL:] + python [in% 5 * PL:] or in ) for the zoom range (1, 10)])
The output is:
[ ' 1 ' , ' 2 ' , ' java ' , ' 4 ' , ' python ' , ' java ' , ' 7 ' , ' 8 ' , ' java ' ]
- Slicing operation i% 3 * jl and i% 5 * pl i only divisible by 3 or 5 when only non-null string, when i is divisible by 3, the complete output string java, i can in divisible by 5, the complete output string python
- When either i or i is divisible by 3 can not be divisible by 5, or the work, the output i
- The overall conversion to a string into the list