<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://fungur.eu/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%2FIf</id>
	<title>Python/If - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://fungur.eu/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%2FIf"/>
	<link rel="alternate" type="text/html" href="https://fungur.eu/wiki/index.php?title=Python/If&amp;action=history"/>
	<updated>2026-05-06T13:33:12Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Shea Wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://fungur.eu/wiki/index.php?title=Python/If&amp;diff=410&amp;oldid=prev</id>
		<title>Suelmann: 1 Version importiert</title>
		<link rel="alternate" type="text/html" href="https://fungur.eu/wiki/index.php?title=Python/If&amp;diff=410&amp;oldid=prev"/>
		<updated>2021-12-20T12:27:45Z</updated>

		<summary type="html">&lt;p&gt;1 Version importiert&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;de&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Nächstältere Version&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version vom 20. Dezember 2021, 14:27 Uhr&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;de&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(kein Unterschied)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Suelmann</name></author>
	</entry>
	<entry>
		<id>https://fungur.eu/wiki/index.php?title=Python/If&amp;diff=409&amp;oldid=prev</id>
		<title>Suelmann am 1. Januar 1970 um 00:00 Uhr</title>
		<link rel="alternate" type="text/html" href="https://fungur.eu/wiki/index.php?title=Python/If&amp;diff=409&amp;oldid=prev"/>
		<updated>1970-01-01T00:00:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
= Python: if statements, several ways =&lt;br /&gt;
&lt;br /&gt;
For this example, we will consider adult people over 18, otherwise, are children.&lt;br /&gt;
&lt;br /&gt;
1) Basic way&lt;br /&gt;
&lt;br /&gt;
Option A&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
if age &amp;gt;= 18:&lt;br /&gt;
  typeOfPerson = &amp;quot;adult&amp;quot;&lt;br /&gt;
else:&lt;br /&gt;
  typeOfPerson = &amp;quot;child&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can assign a default value and change it only if a condition is met.&lt;br /&gt;
&lt;br /&gt;
Option B&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
typeOfPerson = &amp;quot;child&amp;quot; #default value&lt;br /&gt;
if age &amp;gt;= 18:&lt;br /&gt;
  typeOfPerson = &amp;quot;adult&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Option A is better than option B for code optimization, assuming that the probability of either is not very far (Thanks to Arturo Moysen for this comment).&lt;br /&gt;
&lt;br /&gt;
2) Inline if (result = x if condition else y)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
typeOfPerson = &amp;quot;adult&amp;quot; if age &amp;gt;= 18 else &amp;quot;child&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Inline if (result = condition and x or y)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
typeOfPerson = age &amp;gt;= 18 and &amp;quot;adult&amp;quot; or &amp;quot;child&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Inline with tuple, (on_false, on_true)[condition]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
typeOfPerson = (&amp;quot;child&amp;quot;, &amp;quot;adult&amp;quot;)[age &amp;gt;= 18]&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Condition can be anything that evaluates to a Boolean. It is then treated as an integer since it is used to index the tuple: False == 0, True == 1, which then selects the right item from the tuple.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[KategorieWissen]]&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>Suelmann</name></author>
	</entry>
</feed>