0% found this document useful (0 votes)
13 views

Py Exp No.1

The document outlines an experiment focused on implementing various types of operators in Python, including arithmetic, comparison, logical, assignment, membership, identity, and bitwise operators. It provides an introduction to Python, its applications, and the syntax compared to other programming languages. The conclusion emphasizes the real-world use cases of these operators in programming scenarios.

Uploaded by

ranatirth7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Py Exp No.1

The document outlines an experiment focused on implementing various types of operators in Python, including arithmetic, comparison, logical, assignment, membership, identity, and bitwise operators. It provides an introduction to Python, its applications, and the syntax compared to other programming languages. The conclusion emphasizes the real-world use cases of these operators in programming scenarios.

Uploaded by

ranatirth7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No.

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

Title: Program to implementation of different types of operators in python accepting values


from users.

Aim: To write a program to perform operations by accepting values from users

Objective: To introduce basic concepts in Python

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:

●​ web development (server-side),


●​ software development,
●​ mathematics,
●​ system scripting.

What can Python do?

●​ Python can be used on a server to create web applications.


●​ Python can be used alongside software to create workflows.
●​ Python can connect to database systems. It can also read and modify files.
●​ Python can be used to handle big data and perform complex mathematics.
●​ Python can be used for rapid prototyping, or for production-ready software
development.

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 Syntax compared to other programming languages

●​ 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.

1.​ Arithmetic Operators: Arithmetic operators are used to perform mathematical


operations like addition, subtraction, multiplication, etc.

2.​ Assignment Operators: Assignment operators are used to assign values to variables.

3.​ Comparison Operators: Comparison operators compare two values/variables and


return a boolean result: True or False.

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:

1. Arithmetic Operators (+, -, *, /, //, %, **)

●​ Use: Perform basic mathematical operations like addition, subtraction, multiplication,


division, and exponentiation. Commonly used in scenarios like calculating totals,
prices, or mathematical modeling.

2. Comparison Operators (==, !=, >, <, >=, <=)

●​ 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: Combine multiple conditions in decision-making. Used in situations like


validating if a user is eligible for both a discount and free shipping based on multiple
criteria.

4. Assignment Operators (=, +=, -=, *=, /=, etc.)

●​ 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.

5. Membership Operators (in, not in)

●​ 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.

6. Identity Operators (is, is not)

●​ 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.

7. Bitwise Operators (&, |, ^, ~, <<, >>)

●​ Use: Perform bit-level operations on integers. Used in low-level programming for


tasks like data encryption, setting flags, or manipulating hardware registers.

8. Ternary Conditional Operator (x if condition else y)

●​ 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.

You might also like