Comparison between Python, C and Java, Python, and CJava
First, perform a Python test:
1 #! /Usr/bin/env python 2 # coding = UTF-8 3 ''' 4 isosceles triangle 5 ''' 6 for I in range ): 7 print ''' * (6-i), '* I 8 9''' 10 99 multiplication table 11''' 12 for I in range ): 13 for j in range (1, 10): 14 if I >=j: 15 print '% s * % s = % s \ t' % (I, j, I * j), 16 print '\ N'Python
The following is a comparison Program (calculate 1 ~ A multiple of 7 in 100 already has a number with 7 ):
~ 1. Python only uses one sentence of code.
1 s = [x for x in range (1,101) if x % 7 = 0 or ('7' in str (x)]
~ 2. The C language is as follows:
1 #include<stdio.h> 2 3 int main() 4 { 5 int i=0; 6 for (i=0;i<101;i++) 7 { 8 if(i%7==0 || i%10==7 || (i/10)==7) 9 {10 printf("%d\t",i);11 }12 }13 return 0;14 }
~ 3. Followed by Java:
1 class Test{ 2 public static void main(String[] args) 3 { 4 for(int i=1;i<101;i++) 5 { 6 if(i%7==0 || i%10==7 || (i/10)==7) 7 { 8 System.out.println(i); 9 }10 }11 }12 }
Summary: Python sometimes saves time and brain cells!