Assignment - 1
Assignment - 1
PYTHON
ASSIGNMENT - I
Submited by
Suman Mistri
DCST
ROLL - 47
Reg. no - D232406827
ASSIGNMENT - I
(PYTHON)
1. Define Phython .
Ans- Python is a high-level, interpreted programming
language created by Guido van Rossum in 1991. Known for
its simplicity and readability, Python supports multiple
programming paradigms, including object-oriented,
procedural, and functional programming. It features
dynamic typing and automatic memory management.
Python's extensive standard library and vibrant
community make it suitable for diverse applications such
as web development, data science, machine learning,
automation, and more. Its cross-platform nature allows it
to run on different operating systems, making Python
highly versatile and one of the most popular programming
languages worldwide.
Interactive mode
executes code line by Script mode runs the
Execution
line, giving instant entire script at once.
feedback.
Interactive mode is
Script mode is better for
Use suited for testing and
writing full programs.
small tasks.
5. Bitwise Operators
Definition: These operators perform operations on the
binary (bit) representation of integers.
Operators: & (AND), | (OR), ^ (XOR), ~ (NOT), << (left
shift), >> (right shift)
(PYTHON)
6. Identity Operators
Definition: These operators check whether two
variables refer to the same object in memory.
Operators: is, is not
7. Membership Operators
Definition: These operators test if a value is a member
(element) of a sequence, such as strings, lists, or tuples.
Operators: in, not in
Components:
Operands: The values or variables involved, like 5 and 3
in 5 + 3.
Operators: Symbols that define operations, such as +
for addition or == for comparison.
Functions: Functions used within expressions, like
max(10, 20), which evaluates to the maximum of the
two numbers.
Types:
1. Arithmetic Expressions: Perform mathematical
operations, e.g., 7 * (2 + 3) evaluates to 35.
2. Relational Expressions: Compare values, e.g., 10 > 5
results in True.
3. Logical Expressions: Combine boolean values, e.g.,
(True and False) evaluates to False.
4. Conditional Expressions: Short for if-else logic, e.g., x if
x > 0 else -x.
Example:
numbers = [5, 8, 12, 15, 20]
continue Statement :
The continue statement skips the rest of the code
inside the loop for the current iteration and moves to the
next iteration of the loop.
Example:
numbers = [5, 8, 12, 15, 20]
def is_prime(number):
"""Check if a number is a prime number."""
if number <= 1:
return False # Numbers less than or equal to 1 are not prime
if number <= 3:
return True # 2 and 3 are prime numbers
if number % 2 == 0 or number % 3 == 0:
return False # Numbers divisible by 2 or 3 are not prime
return True
Syntax:
if condition:
# Code to execute if the condition is True
Example:
age = 18
def is_palindrome(s):
"""Check if the given string is a palindrome."""
if is_palindrome(user_input):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
for Loop :
for i in range(5):
print("i is:", i)
Ans-
Continue statement :
The continue statement skips the rest of the code
inside the loop for the current iteration and proceeds
with the next iteration of the loop.
Pass statement :
The pass statement is a null operation. It is used as a
placeholder for future code. It does nothing when
executed and is often used when a statement is
syntactically required but you have no code to execute.
Use Case: Useful when you are planning to implement
functionality later but need to maintain the syntax
structure of your code.
(PYTHON)
break statement :
The break statement terminates the nearest
enclosing loop (either for or while) and transfers control
to the statement immediately following the loop.