Conditional Statements
Decision-making statements in programming languages decide the direction(Control Flow) of the flow of program execution.
Python If-Else
In a conditional if Statement the additional block of code is merged as an else statement which is performed when if condition is false.
# python program to illustrate If else statement
i = 20
if (i < 15):
print("i is smaller than 15")
else:
print("i is greater than 15")
print("i'm not in if and not in else Block")
Output:
i is greater than 15
i'm not in if and not in else Block
Python For Loop
The Python For loop is used for sequential traversal, that is, iterating over an iterable such as a String, Tuple, List, Set, or Dictionary. For loops in Python only support collection-based iteration.
# Python program to illustrate
# Iterating over a list
l = ["geeks", "for", "geeks"]
for i in l:
print(i)
Output:
geeks
for
geeks
Python While Loop
The Python while Loop is used to execute a set of statements repeatedly until a condition is met. When the condition is met, the line immediately following the loop in the program is run.
# Python program to illustrate
# while loop
count = 0
while (count < 3):
count = count + 1
print("Hello Geek")
Output:
Hello Geek
Hello Geek
Hello Geek
For more read, refer this break, continue, and pass in Python
Python Cheat sheet (2024)
Python is one of the most widely-used and popular programming languages, was developed by Guido van Rossum and released first in 1991. Python is a free and open-source language with a very simple and clean syntax which makes it easy for developers to learn Python. It supports object-oriented programming and is most commonly used to perform general-purpose programming. Python is used in several domains like Data Science, Machine Learning, Deep Learning, Artificial Intelligence, Scientific Computing Scripting, Networking, Game Development Web Development, Web Scraping, and various other domains.
To give a comprehensive overview of Python programming, we made a Python Cheat Sheet for Python programmers. In this Cheat Sheet of Python, you’ll learn all the basic to advanced topics and concepts of Python, like Python data types, Python for loop, Python slice, python map function, python dictionary, Python File Handling, etc.
Python Cheat sheet
- What is Python?
- Python Input
- Operators in Python
- Python Comment
- DataType in Python
- Python String
- Conditional Statements
- Python Functions
- Python BuildIn Function
- Python RegEx
- File Handling in Python
- Try and Except Statement
- Python OOPs Concepts
- Python Modules
- Python Interview Questions Answers
- Python Cheat Sheet – FAQs