In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of the comparison of Python and Java grammar, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Python is a widely used interpretive, high-level, general-purpose programming language created by Guido Van Rosum. The first edition was released in 1991. You can think of it as an improved LISP that incorporates the advantages of some other programming languages, such as object orientation. Python's design philosophy emphasizes the readability of code and concise syntax (especially using space indentation to divide code blocks rather than using curly braces or keywords). Allows developers to express ideas in less code than C++ or Java,Python. Whether it is small or large programs, the language tries to make the structure of the program clear.
Java is a widely used computer programming language, which has the characteristics of cross-platform, object-oriented and generic programming. It is widely used in enterprise Web application development and mobile application development. The style of the Java programming language is very similar to the C++ language. Inherit the core of the object-oriented technology of C++ language, abandon the error-prone pointers and replace them with references; remove operator overloading and multiple inheritance features in C++ and replace them with interfaces; add garbage collector function. Generic programming, type-safe enumerations, indefinite length parameters, and automatic loading / unboxing features were introduced in Java SE version 1.5. Sun Microsystem's interpretation of the Java language is: "Java programming language is a simple, object-oriented, distributed, interpretive, robust, system-independent, portable, high-performance, multithreaded and dynamic language."
So what's the grammatical difference between Python and Java? let's take a look at it with a few vivid examples.
Goal 1: output hello,world
Python version
Print ("hello,world")
Java version
Public class HelloWorld {/ / the HelloWorld here needs to be the same as the file name public static void main (String [] args) {System.out.println ("hello,world");}}
Goal 2: get keyboard input and output
Python version
Name = input ("Please enter your name:") print (name)
Java version
Import java.util.Scanner;public class inputstr {public static void main (String [] args) {System.out.println ("Please enter your name:"); String name = new Scanner (System.in). Next (); System.out.println (name);}}
Goal 3: output a random number from 1 to 10
Python version
Import randomprint (random.randint (1jre 10))
Java version
Import java.util.Random;public class prandom {public static void main (String [] args) {System.out.println (new Random () .nextInt (10) + 1)}}
Goal 4: specify a list or array, [51, 22, 93, 17, 77, 31, 44, 55, 20], please sort it quickly
Python version
Def quicksort (lis): if len (lis)
< 2: return lis mid = lis[len(lis)//2] lis.remove(mid) left, right = [], [] for li in lis: if li >= mid: right.append (li) else: left.append (li) return quicksort (left) + [mid] + quicksort (right) if _ _ name__ = "_ _ main__": li = [51, 22, 93, 17, 77, 31, 44, 55, 20] newl = quicksort (li) print (newl)
Java version
Import java.util.ArrayList;public class quickpractise {public static void main (String [] args) {int list [] = {51, 22, 93, 17, 77, 31, 44, 55, 20}; ArrayList lis = new ArrayList (); for (int iTuno)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.