Variables: -
Variables are used to store data in memory for subsequent usage in the application. In Python, you don't need to declare a variable before using it; instead, use the assignment operator (=) to assign a value to it. As an example:
In the above example, we assigned the variables x, y, and name the values 10, 3.14, and "John," respectively. Python is a dynamically typed language, thus you don't have to define the type of a variable when you declare it. Python will deduce the type automatically based on the value you supply to it.
Data Types: -
In Python,
data types such as integers, floating-point numbers, texts, booleans, and more
complicated data structures such as lists, tuples, and dictionaries are
available. Here are a couple such examples:
In this example, we make variables of various data kinds. The first four variables are simple data types: x is an integer, y is a float, name is a text, and is true is a boolean. More complicated data structures are also created: my list and my list2 are lists, my tuple and my tuple2 are tuples, and my dict is a dictionary.
Operators: -
Operators
are used to manipulate variables and values. Arithmetic operators, comparison
operators, logical operators, and assignment operators are all available. Here
are a couple such examples:
The second
set of operators includes equal to (==), not equal to (!=), greater than
(>), less than (), greater than or equal to (>=), and less than or equal
to (==).
Control
Structures: -
Control
structures are used to direct the execution of a programme. If/else statements,
loops, and functions are examples. Here are a couple such examples:
The for loop is the second control structure. It iterates over a series of objects, such as a list or a tuple, and executes a block of code for each item in the sequence.
The while
loop is the third control structure, and it executes a block of code repeatedly
as long as a condition is true.
The break statement, which is used inside a loop to break out of the loop and stop the iteration when a given condition is fulfilled, is the fourth control structure.
The continue statement, which is used inside a loop to skip an iteration and go on to the next item in the sequence when a given condition is fulfilled, is the fifth control structure.
The
try-except statement is the sixth control structure, and it is used to manage
mistakes and exceptions in programmes. The code in the try block may throw an
exception, and the code in the except block handles the exception. We catch the
ZeroDivisionError exception in this example, which occurs when we try to divide
an integer by zero.
0 Comments