Erinevus lehekülje "JavaPython" redaktsioonide vahel
11. rida: | 11. rida: | ||
!Python | !Python | ||
|- | |- | ||
− | |<u> | + | |<u>Trükkimine</u> |
− | |<u> | + | |<u></u> |
|- | |- | ||
|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. | |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. | ||
21. rida: | 21. rida: | ||
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. | 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. | ||
|- | |- | ||
− | |<u> | + | |<u>Koodi pikkus</u> |
− | |<u> | + | |<u></u> |
|- | |- | ||
|abounding in words; using or containing more words than are necessary | |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 | |expressing much in a few words. Implies clean-cut brevity, attained by excision of the superfluous | ||
|- | |- | ||
− | |<u> | + | |<u>Kompaktsus</u> |
− | |<u> | + | |<u></u> |
+ | |- | ||
+ | | | ||
+ | | | ||
+ | |- | ||
+ | |<u>Tabulatsioon</u> | ||
+ | |<u></u> | ||
+ | |- | ||
+ | |Javas ei ole mitte mingit vahet kas joondada koodis iga käsk eri kaugusele, kirjutada nad üksteise järele kõik ühe rea peale või lihtsalt ritta üksteise alla. | ||
+ | |Tabulatsioon on väga oluline | ||
|} | |} | ||
Redaktsioon: 19. jaanuar 2016, kell 13:55
Sissejuhatus
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 |
---|---|
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. |
Koodi pikkus | |
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 |
Kompaktsus | |
Tabulatsioon | |
Javas ei ole mitte mingit vahet kas joondada koodis iga käsk eri kaugusele, kirjutada nad üksteise järele kõik ühe rea peale või lihtsalt ritta üksteise alla. | Tabulatsioon on väga oluline |
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
10. Tsükkel
11. Sõnastikud
12. Funktsioonid
14. Moodulid
15. Objektid