 Hallo, hier bin ich wieder. Im [letzten Artikel](https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-3-das-erste-programm#comments) habe ich mit Python Rechenaufgaben gelöst und mein erstes Programm geschrieben (**Hello World**). Ich habe gelernt was es für Operatoren gibt und wie man ein Programm ausführt. Und es bleibt interessant... Weiter gehts... <center></center> --- Hier ist eine Übersicht über bisherigen Artikel: 1. **[Einführung, Vor- und Nachteile](https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-1-einfuehrung-vor-und-nachteile)** 2. **[Wie du Python installierst](https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-2-wie-du-python-installierst)** 3. **[Das erste Programm](https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-3-das-erste-programm)** --- In diesem Teil der Serie will ich **Variablen** kennenlernen. # Was ist eine Variable? Eine Variable ist wie ein Behälter, in dem man Information aufbewahren kann. Auf Wunsch kann man die Informationen abrufe, ändern oder sogar löschen. So sieht eine einfache Variable aus: ``` test = 12 ``` Ich habe der Variablen **test** den Wert **12** gegeben. Möchte ich den Wert jetzt anzeigen, muss ich nur folgendes eingeben: ``` print(test) ``` Nachdem man das Programm ausgeführt hat, bekommt man den Wert **12** angezeigt. --- # Variablen zusammenrechnen In diesem Beispiel sollen die Kosten für **Miete**, **Strom** und **Heizung** ausgerechnet werden.  Dafür erstelle ich eine neue Python-Datei, wie im letzten Artikel beschrieben. Dort füge ich folgende Variablen ein: ``` miete = 700 strom = 90 heizung = 85 ``` Nun kann ich alle 3 Variablen in eine Variable zusammenfassen. Die nenne ich **gesamtkosten**. Es werden alle variablen zusammengerechnet. ``` gesamtkosten = miete + strom + heizung ``` Um jetzt die Gesamtkosten anzuzeigen, gebe ich noch folgenden Befehl: ``` print(gesamtkosten) ``` Nachdem ich das Programm ausgeführt habe, bekomme ich **875** als Ergebnis. Wenn ich es so schreibe: ``` print("Gesamtkosten: ", gesamtkosten) ``` Dann steht vor dem Ergebnis noch das Wort **Gesamtkosten:**. Das sieht schon etwas besser aus. <center></center> --- # Variablen löschen So löscht man eine Variable: ``` del test ``` In meinem Beispiel habe ich die Variable **test** gelöscht. --- # Variable benennen eine Variable kannst du beliebig benennen, du musst nur folgende Regeln befolgen: 1. Du kannst nur Buchstaben, Zahlen und Unterstriche (_) benutzen. 2. Es dürfen keine Leerzeichen und andere Sonderzeichen benutzt werden. 3. Es darf nicht mit einer Zahl beginnen. 4. Es dürfen nicht von Python reservierte Keywords benutzt werden. Hier eine Auflistung mit allen Python-Keywords: **False, class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, raise** **Noch etwas:** Es sind jeweils unterschiedliche Variablen, wenn sich die Groß- und Kleinschreibung unterscheidet. Siehe Beispiel unten. ``` miete = 800 Miete = 700 miETE = 900 ``` Es ist jeweils eine neue Variable. --- # Einige Fragen habe ich noch: - Ist es egal ob man `miete = 800` oder `miete=800` schreibt? - Ist es egal ob man `9 + 7` oder `9+7` schreibt? - Ist es egal ob man `print ( miete )` oder `print(miete)` Und wie ist es am besten zu schreiben? --- Icons von [Iconmonstr](https://iconmonstr.com/)
author | rilc0n |
---|---|
permlink | python-fuer-anfaenger-4-variablen |
category | deutsch |
json_metadata | {"tags":["deutsch","german","python","tutorial","anleitung"],"image":["https://steemitimages.com/DQmTNVuCKqxsELCEU1zXEZbxET12Jc1XwBnKaD8AQxM1W6M/python-4.png","https://steemitimages.com/DQmSfMcHv5asn3zTyLtkbGwD7XYRa6gumTHhfw7RMPZ19SC/interesting.gif","https://steemitimages.com/DQmZQP9zdR28vfYgzYK1oCnvRHsUZYhh4X7491jinmz32HF/gesamtkosten.png","https://steemitimages.com/DQmbcg64sWdAsjASbbwpP3DX26zD4Xhm3YASLKGL22ehYi9/python4.png"],"links":["https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-3-das-erste-programm#comments","https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-1-einfuehrung-vor-und-nachteile","https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-2-wie-du-python-installierst","https://steemit.com/deutsch/@rilc0n/python-fuer-anfaenger-3-das-erste-programm","https://iconmonstr.com/"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-02-01 18:03:18 |
last_update | 2018-02-01 18:03:18 |
depth | 0 |
children | 7 |
last_payout | 2018-02-08 18:03:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 2.170 HBD |
curator_payout_value | 0.698 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,884 |
author_reputation | 107,632,740,804 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 34,190,085 |
net_rshares | 465,036,966,440 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
shaka | 0 | 363,827,834,097 | 10% | ||
felixxx | 0 | 83,873,508,571 | 25% | ||
smasher | 0 | 517,622,064 | 10% | ||
dorabot | 0 | 458,893,701 | 1% | ||
igorbolchin | 0 | 59,055,359 | 100% | ||
vorobevin | 0 | 195,235,578 | 100% | ||
tleem | 0 | 56,249,422 | 100% | ||
naturicia | 0 | 7,154,168,455 | 50% | ||
underpants | 0 | 2,877,895,177 | 100% | ||
thilobillerbeck | 0 | 606,948,634 | 100% | ||
drookyn | 0 | 4,188,121,616 | 100% | ||
serenecheck | 0 | 677,637,132 | 100% | ||
trashing88 | 0 | 543,796,634 | 100% |
Gutes Anfänger Tutorial! Eventuell könntest du noch auf die verschiedenen Typen von Variablen eingehen (int, str, list, etc.). Um deine Fragen zu beantworten: 3x ja & wie du es schreibst bleibt am Ende dir überlassen 😊
author | drookyn |
---|---|
permlink | re-rilc0n-python-fuer-anfaenger-4-variablen-20180201t185529848z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"app":"steemit/0.1"} |
created | 2018-02-01 18:55:27 |
last_update | 2018-02-01 18:55:27 |
depth | 1 |
children | 1 |
last_payout | 2018-02-08 18:55:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.048 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 226 |
author_reputation | 435,919,623,109 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,200,264 |
net_rshares | 8,173,628,716 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
security101 | 0 | 3,625,168,631 | 100% | ||
rilc0n | 0 | 4,548,460,085 | 100% |
Ich werde mal im nächsten Artikel über die Typen schreiben. Muss es selber noch verstehen 😂 Danke...
author | rilc0n |
---|---|
permlink | re-drookyn-re-rilc0n-python-fuer-anfaenger-4-variablen-20180201t190950245z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"app":"steemit/0.1"} |
created | 2018-02-01 19:09:51 |
last_update | 2018-02-01 19:09:51 |
depth | 2 |
children | 0 |
last_payout | 2018-02-08 19:09:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 100 |
author_reputation | 107,632,740,804 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,203,016 |
net_rshares | 0 |
Ist eigentlich schlechter Stil, aber hast du meinen Python Artikel gelesen ? https://steemit.com/steemdev/@felixxx/125-steem-developer-bounty-inside-python
author | felixxx |
---|---|
permlink | re-rilc0n-python-fuer-anfaenger-4-variablen-20180203t235159908z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"links":["https://steemit.com/steemdev/@felixxx/125-steem-developer-bounty-inside-python"],"app":"steemit/0.1"} |
created | 2018-02-03 23:52:00 |
last_update | 2018-02-03 23:52:00 |
depth | 1 |
children | 0 |
last_payout | 2018-02-10 23:52:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 156 |
author_reputation | 214,424,157,741,799 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,756,621 |
net_rshares | 0 |
Ich weiß nicht, was dein Ziel letztendlich ist, aber ich würde es gut finden, wenn du am Ende bei Steempython angelangst und das verstehst. Dann fällt mir das nämlich auch leichter zu verstehen :D Gruß Naturicia
author | naturicia |
---|---|
permlink | re-rilc0n-python-fuer-anfaenger-4-variablen-20180202t195147831z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"app":"steemit/0.1"} |
created | 2018-02-02 19:51:48 |
last_update | 2018-02-02 19:51:48 |
depth | 1 |
children | 1 |
last_payout | 2018-02-09 19:51:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.028 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 212 |
author_reputation | 4,115,107,733,481 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,475,395 |
net_rshares | 4,635,493,954 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
rilc0n | 0 | 4,635,493,954 | 100% |
Das werde ich sicherlich mir anschauen, nur dauert es noch etwas :D
author | rilc0n |
---|---|
permlink | re-naturicia-re-rilc0n-python-fuer-anfaenger-4-variablen-20180202t195320180z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"app":"steemit/0.1"} |
created | 2018-02-02 19:53:24 |
last_update | 2018-02-02 19:53:24 |
depth | 2 |
children | 0 |
last_payout | 2018-02-09 19:53:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 67 |
author_reputation | 107,632,740,804 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,475,685 |
net_rshares | 0 |
Bei deinen Fragen kann man sich denke ich gut an [PEP8](https://www.python.org/dev/peps/pep-0008/) orientieren. [PEP8](https://www.python.org/dev/peps/pep-0008/) ist praktisch eine Sammlung von Formatierungs-Richtlinien. :)
author | nico.neu |
---|---|
permlink | re-rilc0n-python-fuer-anfaenger-4-variablen-20180201t190156518z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"links":["https://www.python.org/dev/peps/pep-0008/"],"app":"steemit/0.1"} |
created | 2018-02-01 19:01:57 |
last_update | 2018-02-01 19:01:57 |
depth | 1 |
children | 1 |
last_payout | 2018-02-08 19:01:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.028 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 223 |
author_reputation | 1,943,180,479 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,201,515 |
net_rshares | 4,642,728,688 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
rilc0n | 0 | 4,642,728,688 | 100% |
Danke, PEP8 kannte ich noch nicht. Werde mir das auf jeden Fall mal genauer anschauen :)
author | rilc0n |
---|---|
permlink | re-niconeu-re-rilc0n-python-fuer-anfaenger-4-variablen-20180201t190732397z |
category | deutsch |
json_metadata | {"tags":["deutsch"],"app":"steemit/0.1"} |
created | 2018-02-01 19:07:33 |
last_update | 2018-02-01 19:07:33 |
depth | 2 |
children | 0 |
last_payout | 2018-02-08 19:07:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 88 |
author_reputation | 107,632,740,804 |
root_title | "Python für Anfänger #4 - Variablen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,202,594 |
net_rshares | 0 |