Erinevus lehekülje "JavaPython" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
47. rida: 47. rida:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
|<syntaxhighlight lang="python" line="1" >
+
|<syntaxhighlight lang="python" line="2" >
print "Hello, world!"
 
</syntaxhighlight>
 
 
 
 
 
<syntaxhighlight lang="python" line="2" >
 
 
print("Hello, world!") # Python version 3
 
print("Hello, world!") # Python version 3
 
</syntaxhighlight>
 
</syntaxhighlight>

Redaktsioon: 19. jaanuar 2016, kell 13:36

Sissejuhatus

Python-vs-java.jpg

Selle lehekülje eesmärgiks on võrrelda erinevaid komponente Java ja Pythoni programmeerimiskeelte vahel. Kuigi antud leht on mõeldud Tallinna Tehnikaülikooli informaatikaeriala tudengitele õppevahendiks, sobib seda uurida ka kõigil, kes tahavad võrrelda kahte programmeerimiskeelt. Igal alamleheküljel on toodud võrdlusena komponente nii Java kui ka Pythoni keeles.

Küsimuste korral pöörduda ago.luberg@ttu.ee


Java Python
staatiline trükkimine dünaamiline trükkimine
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception.That’s what it means to say that Java is a statically typed language.

Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn’t remember its type, and must be explicitly cast to the desired type.

In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That’s what it means to say that Python is a dynamically typed language.

Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required.

ohtralt sõnu napisõnaline
abounding in words; using or containing more words than are necessary expressing much in a few words. Implies clean-cut brevity, attained by excision of the superfluous
ebakompaktne äärmiselt kompaktne


Näide "Hello World"

Java Python
<syntaxhighlight lang="java" line="1" >

public class HelloWorld {

   public static void main (String[] args)
   {
       System.out.println("Hello world!");
   }

} </syntaxhighlight>

<syntaxhighlight lang="python" line="2" >

print("Hello, world!") # Python version 3 </syntaxhighlight>

Sisukord

1. Programmid

2. Muutujad

3. Andmetüübid

4. Järjend

5. Sõne

6. "Array"

7. Operaatorid

8. Sisendid ja väljundid

9. Tingimuslaused

10. Tsükkel

11. Sõnastikud

12. Funktsioonid

13. Operatsioonid failidega

14. Moodulid

15. Objektid