schule:python_fuer_c-sharp_programmierer
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| schule:python_fuer_c-sharp_programmierer [2016-04-24 08:17] – angelegt marco.bakera | schule:python_fuer_c-sharp_programmierer [2017-04-19 06:39] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== Python für C# | ||
| + | Eine kleine Übersicht über Unterschiede bei der Syntax von [[die_programmiersprache_c-sharp|C# | ||
| + | |||
| + | **Kommentare** | ||
| + | |||
| + | // C# | ||
| + | # Python | ||
| + | |||
| + | **Zuweisungen** | ||
| + | |||
| + | C# | ||
| + | int iVar = 0; | ||
| + | |||
| + | Python | ||
| + | iVar = 0 | ||
| + | |||
| + | |||
| + | **Verzweigungen** | ||
| + | |||
| + | C# | ||
| + | if(iVar == 0) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | if iVar == 0: | ||
| + | print(" | ||
| + | |||
| + | |||
| + | C# | ||
| + | if(iVar > 0 && iVar < 5) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | if iVar > 0 and iVar < 5: | ||
| + | print(" | ||
| + | | ||
| + | oder kürzer | ||
| + | |||
| + | if 0 < iVar < 5: | ||
| + | print(" | ||
| + | |||
| + | |||
| + | **Methoden ** | ||
| + | |||
| + | C# | ||
| + | public void addiereEins(int i) | ||
| + | { | ||
| + | return i + 1; | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | def addiereEins(self, | ||
| + | return i + 1 | ||
| + | |||
| + | |||
| + | **Schleifen** | ||
| + | |||
| + | C# | ||
| + | for(int i=0; i<5; i++) | ||
| + | { | ||
| + | Console.WriteLine(i); | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | for i in range(5): | ||
| + | print(i) | ||
| + | |||
| + | C# | ||
| + | int b = 3; | ||
| + | while(b > 0) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | b = 3 | ||
| + | while b > 0: | ||
| + | print(" | ||
| + | |||
| + | |||
| + | **Arrays** | ||
| + | |||
| + | C# | ||
| + | int[] arr = new int[2]; | ||
| + | arr[0] = 5; | ||
| + | arr[1] = 6; | ||
| + | |||
| + | Python | ||
| + | arr = [5, 6] | ||
| + | |||
| + | C# | ||
| + | for(int i=0; i< | ||
| + | { | ||
| + | Console.WriteLine(arr[i]); | ||
| + | } | ||
| + | |||
| + | Python | ||
| + | for i in range( len(arr) ): | ||
| + | print( arr[i] ) | ||
| + | |||
| + | etwas kürzer | ||
| + | |||
| + | for a in arr: | ||
| + | print(a) | ||
| + | |||
| + | |||
| + | Hier sind noch einmal alle Befehle zusammengefasst. Mit einem Klick auf " | ||
| + | |||
| + | < | ||
| + | |||
| + | <iframe src=" | ||
| + | |||
| + | </ | ||
