Overview: Set up two arrays/lists, List A is [three-to-one], List B is [' A ', ' B ', ' C '], put them on one-to print, but do not print "3:c" this pair.
Python version:
"' Created on 2014-11-2@author:administrator '" Class Myarray:def __init__ (self): SELF.A = range (1,4) se lf.b = [' A ', ' B ', ' C '] def getValue (self): TMP = {} for I in Self.a:tmp[str (i)] = Self.b[i-1] return Tmpa = MyArray () x = A.getvalue () for i in x:if i = = ' 3 ': Continue print '%s is:%s '% (I,x[i])
Java Edition:
public class MyArray {public static void main (String[]args) {int[] a = new int[3];char[] b = new char[]{' A ', ' B ', ' C '};for (in T i=0;i<3;i++) {a[i] = i+1;} for (int i=0;i<b.length;i++) {if (i==2) {continue;} System.out.println (a[i]+ "is:" +b[i]);}}
About dictionary formatting in the Python version:
Reference:
In [1]: Phonebook = {: 123,: 456,: 789}in [2]:% phonebookout[2]:
It is not possible to use: "%s is:% (key)"% (string,dict) format dictionary format string, and in the preceding case, the dictionary key must be a string, otherwise it cannot be formatted.
When writing the Python version, I suddenly realized that I had forgotten something: return causes the function to return a value and stop the iteration or loop, so the code is problematic:
def error (list): For i in list:if xxx:return xxx #只能输出一个值
#python +java# the same function code in two language implementations