Python is a high-level programming language that has gained immense popularity due to its simplicity, versatility, and readability. Developed by Guido van Rossum and first released in 1991, Python has evolved into one of the most widely used programming languages worldwide. Its design philosophy emphasizes code readability and simplicity, making it an ideal choice for beginners and experienced programmers alike. In this comprehensive exploration, we'll delve into the various aspects of Python, including its history, features, syntax, applications, libraries, and future prospects.
**Table of Contents:**
1. Introduction to Python
2. History of Python
3. Features of Python
4. Python Syntax
5. Data Types and Structures
6. Control Flow and Functions
7. Object-Oriented Programming
8. Python Standard Library
9. Python for Scientific Computing
10. Web Development with Python
11. Data Science and Machine Learning
12. Python in Artificial Intelligence
13. Automation and Scripting
14. Python in Education
15. Future of Python
**1. Introduction to Python:**
Python is a general-purpose, interpreted, and dynamically typed programming language known for its simplicity and ease of learning. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python's syntax is designed to be clear and readable, resembling pseudo-code, which makes it accessible to beginners and facilitates rapid development.
**2. History of Python:**
Python was conceived in the late 1980s by Guido van Rossum, a Dutch programmer, who aimed to create a language that would be easy to learn and use. The first version of Python, Python 0.9.0, was released in 1991. Python 2.x series gained widespread adoption in the following years, with Python 2.7 being the final release in the 2.x series. Python 3, a major revision of the language, was released in 2008 to address various inconsistencies and improve features.
**3. Features of Python:**
Python boasts several features that contribute to its popularity:
- Simple and Readable Syntax: Python's syntax is intuitive and readable, making it easy to write and understand code.
- Dynamically Typed: Python is dynamically typed, allowing variables to be assigned without specifying their type explicitly.
- Extensive Standard Library: Python comes with a vast standard library that provides modules and functions for various tasks, eliminating the need for external dependencies.
- Portability: Python code is platform-independent, allowing it to run on different operating systems without modification.
- Interpreted Nature: Python code is executed line by line by the Python interpreter, facilitating rapid prototyping and debugging.
- Object-Oriented: Python supports object-oriented programming principles, enabling the creation of reusable and modular code.
**4. Python Syntax:**
Python syntax is characterized by its use of indentation to define code blocks, rather than curly braces or keywords. Here's an exam
Presiding Officer Training module 2024 lok sabha elections
W4-DecisionMaking.pdf. python document. CS
1. CS114 - Fundamental of Programming
Dr. Nazia Perwaiz
nazia.perwaiz@seecs.edu.pk
vision.seecs.edu.pk
Note: Various contents in this presentation have been taken from different books, lecture notes, and the web. These solely belong to their
owners, and are here used only for clarifying various educational concepts. Any copyright infringement is not intended.
3. Outline
• Python if else
• if statement
• if-else
• nested-if
• if-elif-else ladder
• Short Hand if statement
• Short Hand if-else statement
• Examples and practice
programmes
3
4. Decision-making
• There comes situations in real life when we need to make some decisions and
based on these decisions, we decide what should we do next.
• Similar situations arise in programming also where we need to make some
decisions and based on these decisions we will execute the next block of code.
• Decision-making statements in programming languages decide the direction of the
flow of program execution.
• In Python, if else elif statement is used for decision making
4
5. if statement (one way decision)
• ‘if’ statement is the most simple decision-making statement.
• It is used to decide whether a certain statement or block of statements will be
executed or not i.e if a certain condition is true then a block of statement is
executed otherwise not.
5
6. if statement
• Syntax:
• Here, the condition after evaluation will be either true or false. if statement accepts
boolean values – if the value is true then it will execute the block of statements
below it otherwise not. We can use condition with bracket ‘(‘ ‘)’ also.
6
if condition:
# Statements to execute if condition is true
7. if statement
7
As we know, python uses indentation to identify a block. So the block under an if statement will be
identified as shown in the below example
10. Example: Python if Statement
10
As the condition present in the if statement is false. So, the block below the if statement is not executed.
11. if-else (Two way decision)
• The if statement alone tells us that if a condition is true it will execute a block of
statements and if the condition is false it won’t.
• But what if we want to do something else if the condition is false. Here comes
the else statement.
• We can use the else statement with if statement to execute a block of code when
the condition is false.
11
16. nested-if
• A nested if is an if statement that is the target of another if statement.
• Nested if statements mean an if statement inside another if statement.
• Python allows us to nest if statements within if statements. i.e, we can place an if
statement inside another if statement.
16
21. if-elif-else ladder (three way decision)
• A user can decide among multiple options.
• The if statements are executed from the top down. As soon as one of the
conditions controlling the if is true, the statement associated with that if is executed,
and the rest of the ladder is bypassed.
• If none of the conditions is true, then the final else statement will be executed.
21