Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Getting Started with Python (Part 7): Conditional Statements

Using Conditional Statements in Python In this article, we’ll learn about conditional statements. By using conditional logic, you can control the flow of your program and implement more complex behavior. Boolean Values and C…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Using Conditional Statements in Python



In this article, we’ll learn about conditional statements.


By using conditional logic, you can control the flow of your program and implement more complex behavior.





Boolean Values and Comparison Operators



Before diving into conditional statements, let’s first look at boolean values and comparison operators.





What Are Boolean Values?



A boolean value is a data type that represents only two possible states: true or false.





  • True means something is correct or valid.


  • False means something is incorrect or invalid.



You can think of it like a true/false quiz:


⭕ correct → True, ❌ incorrect → False.



In conditional statements, these boolean values are used to make decisions.





What Are Comparison Operators?



Comparison operators are symbols used to compare two values.


The result of a comparison is always a boolean value: True or False.



Conditional statements use these results to decide whether a block of code should run.



Here are the most common comparison operators:











































Operator Example Meaning
== a == b True if a and b are equal
!= a != b True if a and b are not equal
< a < b True if a is less than b
<= a <= b True if a is less than or equal to b
> a > b True if a is greater than b
>= a >= b True if a is greater than or equal to b




Using Conditional Statements



Now let’s look at how to write conditional statements in Python.





Using the if Statement



Conditional logic in Python is written using the if keyword.


Indentation is very important—it defines the block of code that runs only when the condition is True.




if condition:
code_that_runs_when_condition_is_true






Here’s a simple example using a comparison operator.




age = 18
if age >= 18:
print("You are an adult!")
# Output: You are an adult!






If we change age to 17, the condition becomes False, and nothing is printed.




age = 17
if age >= 18:
print("You are an adult!")
# Output: nothing









Using the else Statement



The else keyword lets you define what happens when the condition is False.




age = 18
if age >= 18:
print("You are an adult!")
else:
print("You are a minor!")
# Output: You are an adult!






If we change age to 17, the else block runs instead.




age = 17
if age >= 18:
print("You are an adult!")
else:
print("You are a minor!")
# Output: You are a minor!









Using the elif Statement



The elif keyword (short for else if) is used when you want to check multiple conditions.



If the first if condition is False, Python checks the elif condition next.




age = 17
if age >= 18:
print("You are an adult!")
elif age >= 15:
print("You are a teenager!")
else:
print("You are a child!")
# Output: You are a teenager!






If all conditions are False, the final else block runs.




age = 14
if age >= 18:
print("You are an adult!")
elif age >= 15:
print("You are a teenager!")
else:
print("You are a child!")
# Output: You are a child!






You can use as many elif statements as you like.


Just remember that conditions are checked from top to bottom, so the order matters.




age = 14
if age >= 18:
print("You are an adult!")
elif age >= 15:
print("You are a teenager!")
elif age >= 6:
print("You are a child!")
else:
print("You are a toddler!")
# Output: You are a child!









Logical Operators



Logical operators allow you to combine multiple conditions into a single decision.




























Operator Example Meaning
not not a Reverses the condition
or a or b True if either condition is True
and a and b True only if both conditions are True





Using not






age = 18
if not age >= 18:
print("You are a minor!")









Using or






age = 25
if age < 18 or age >= 65:
print("You are a minor or a senior! (Discount applied!)")









Using and






age = 25
if age >= 18 and age <= 65:
print("You are an adult! (No discount available!)")









What’s Next?



Thank you for reading!


In the next article, we’ll cover “Working with Multiple Data Types (Part 1)”.


Stay tuned!

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - Getting Started with Python (Part 7): Conditional Statements
id: 3eb34062-13ae-40a1-a4fd-4862f384ddaf
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "Getting Started with Python (P" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Getting Started with Python Part 7 Condi")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Getting Started with Python Part 7 Condi*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Getting Started with Python Part 7 Condi"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Getting Started with Python (Part 7): Co.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Getting Started with Python (Part 7): Conditional Statements

Thematisch verwandte Begriffe: Getting, Started, with, Python · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93647 | An unauthenticated calendar sender can place active markup in a COUNTER …
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag