要求:下面的两个Python列表包含了编程语言和对应的创建时间。请将它们一一对应打印出来。
languages = ["C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"]
years = [1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009]
方法1,for循环:
# for i in range(len(years)):
# print(languages[i],': ',years[i])
方法2,while循环:
# i = 0 # while i < len(years):
# print(languages[i],': ',years[i])
# i += 1
方法3,列表推导式:
# print([(languages[i],': ',years[i]) for i in range(len(years))])
方法4,zip函数:
# for l,y in zip(languages,years):
# print(l+':',y)
运行结果展示: