Py Exp No.1
Py Exp No.1
1
Program to implementation of different types of operators in python
accepting values from users.
Date of Performance:22/01/2025
Date of Submission:19/02/2025
Experiment No. 1
Theory:
What is Python?
Python is a popular programming language. It was created by Guido van Rossum and
released in 1991.
It is used for:
Why Python?
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
● Python runs on an interpreter system, meaning that code can be executed as soon as it
is written. This means that prototyping can be very quick.
● Python can be treated in a procedural way, an object-oriented way or a functional way.
Good to know
● The most recent major version of Python is Python 3, which we shall be using in this
tutorial. However, Python 2, although not being updated with anything other than
security updates, is still quite popular.
● In this tutorial Python will be written in a text editor. It is possible to write Python in
an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or
Eclipse which are particularly useful when managing larger collections of Python
files.
● Python was designed for readability, and has some similarities to the English language
with influence from mathematics.
● Python uses new lines to complete a command, as opposed to other programming
languages which often use semicolons or parentheses.
● Python relies on indentation, using whitespace, to define scope; such as the scope of
loops, functions and classes. Other programming languages often use curly-brackets
for this purpose.
2. Assignment Operators: Assignment operators are used to assign values to variables.
4. Logical Operators: Logical operators are used to check whether an expression
is True or False. They are used in decision-making.
5. Bitwise Operators: Bitwise operators act on operands as if they were strings of binary
digits. They operate bit by bit Bitwise operators act on operands as if they were
strings of binary digits. They operate bit by bit.
6. Membership operators: In Python, in and not in are the membership operators. They
are used to test whether a value or variable is found in a sequence (string, list, tuple,
set and dictionary). In a dictionary, we can only test for the presence of a key, not the
value
7. Identity operators: In Python, is and is not used to check if two values are located at
the same memory location.
It's important to note that having two variables with equal values doesn't necessarily
mean they are identical.
Conclusion: Implementation of different types of operators in python in real word scenario.
Here's a brief overview of different types of operators in Python and their real-world use
cases:
● Use: Compare values and return a boolean result. Used for decision-making, such as
checking if a user is eligible for a discount or if a product is available.
3. Logical Operators (and, or, not)
● Use: Assign values to variables or modify them. Used frequently in scenarios like
updating account balances, applying changes in system settings, or accumulating
results over time.
● Use: Check if a value exists in a sequence (like a list or string). Common in scenarios
such as verifying if a user exists in a database or if a product is in stock.
● Use: Check if two variables refer to the same object in memory. Used for ensuring
that two references point to the same instance in object-oriented programming.
● Use: Condenses an if-else statement into a single line. Useful for making simple
decisions in a more compact and readable form, like assigning values based on
conditions (e.g., discounts or status).
These operators are integral for performing a variety of operations, from basic calculations to
more complex data manipulation and logic handling.