Category: Basic
-
Nested if Statement
Python supports nested if statements which means we can use a conditional if and if…else statement inside an existing if statement. There may be a situation when you want to check for additional conditions after the initial one resolves to true. In such a situation, you can use the nested if construct. Additionally, within a nested if construct, you can include an if…elif…else construct inside another if…elif…else construct. Syntax of…
-
ifelse Statement
Python if else Statement The if-else statement in Python is used to execute a block of code when the condition in the if statement is true, and another block of code when the condition is false. Syntax of if-else Statement The syntax of an if-else statement in Python is as follows − if boolean_expression:# code block to be executed#…
-
if Statement
Python If Statement The if statement in Python evaluates whether a condition is true or false. It contains a logical expression that compares data, and a decision is made based on the result of the comparison. Syntax of the if Statement if expression: # statement(s) to be executed If the boolean expression evaluates to TRUE, then the statement(s) inside…
-
Decision Making
Python’s decision making functionality is in its keywords − if..elif…else. The if keyword requires a boolean expression, followed by colon (:) symbol. The colon (:) symbol starts an indented block. The statements with the same level of indentation are executed if the boolean expression in if statement is True. If the expression is not True (False), the interpreter bypasses the indented block and proceeds…
-
Control Flow
Python program control flow is regulated by various types of conditional statements, loops, and function calls. By default, the instructions in a computer program are executed in a sequential manner, from top to bottom, or from start to end. However, such sequentially executing programs can perform only simplistic tasks. We would like the program to have a decision-making ability,…
-
Booleans
Python Booleans (bool) In Python, bool is a sub-type of int type. A bool object has two possible values, and it is initialized with Python keywords, True and False. Example >>> a=True>>> b=False>>>type(a),type(b)(<class’bool’>,<class’bool’>) A bool object is accepted as argument to type conversion functions. With True as argument, the int() function returns 1, float() returns 1.0; whereas for False, they return 0 and…
-
Numbers
Python has built-in support to store and process numeric data (Python Numbers). Most of the times you work with numbers in almost every Python application. Obviously, any computer application deals with numbers. This tutorial will discuss about different types of Python Numbers and their properties. Python – Number Types There are three built-in number types available in…
-
User Input
Provide User Input in Python In this chapter, we will learn how Python accepts the user input from the console, and displays the output on the same console. Every computer application should have a provision to accept input from the user when it is running. This makes the application interactive. Depending on how it is…
-
Comments
Python Comments Python comments are programmer-readable explanation or annotations in the Python source code. They are added with the purpose of making the source code easier for humans to understand, and are ignored by Python interpreter. Comments enhance the readability of the code and help the programmers to understand the code very carefully. Example If…
-
Operator Precedence
Python Operator Precedence An expression may have multiple operators to be evaluated. The operator precedence defines the order in which operators are evaluated. In other words, the order of operator evaluation is determined by the operator precedence. If a certain expression contains multiple operators, their order of evaluation is determined by the order of precedence.…