Assignment 1
Assignment 1
Ans:-
Easy to Learn and Use – Python has a simple and readable syntax, making it
beginner-friendly.
Interpreted Language – Python executes code line by line, making debugging easier.
Dynamically Typed – No need to declare variable types; Python determines the type
at runtime.
Platform-Independent – Python code can run on different operating systems
without modification.
Open-Source and Free – Available for free and has a large community supporting
development.
Extensive Libraries and Modules – Comes with a rich set of built-in libraries for
various applications.
Object-Oriented and Procedural Support – Supports both object-oriented and
procedural programming paradigms.
High-Level Language – Allows writing code in a human-readable format, reducing
complexity.
Ans:-
What is a Variable?
A variable is a name that refers to a memory location where data is stored such as numbers,
No, Python does not allow explicit declaration of variables before assigning a value.
1. No Need to Declare Type –Python understands it automatically when you assign a value.
2. Type Can Change Anytime – You can store a number in a variable first, then change it to
x = 10 # x is an integer
Ans:-
Data Types include integers (int), floating-point numbers (float), strings (str), lists (list),
tuples (tuple), dictionaries (dict), etc.
age = 25 # Integer
2. Operators
Used to perform operations on variables and values.
Types: Arithmetic (+, -, *, /), Comparison (==, !=, >, <), Logical (and, or, not), etc.
Example: a = 10, b = 5
print(a + b
print(a > b)
Examples:
num = 10
if num > 0:
print("Positive number")
for i in range(5):
print(i)
4. Functions
Example:
def greet(name):
greet("Alice")
Ans:-
What is a Comment?
print("Python is fun!")
Example:-
Ans:-
. Numeric Types
Used for storing numbers.
Integer (int) – Whole numbers (positive or negative).
x = 10 # Integer
Floating-point (float) – Numbers with decimals.
y = 10.5 # Float
Complex (complex) – Numbers with real and imaginary parts.
z = 3 + 4j # Complex number
2. Sequence Types
Used to store multiple values in order.
String (str) – Collection of characters (text).
name = "Python" # String
List (list) – Ordered, changeable collection of items.
fruits = ["Apple", "Banana", "Cherry"] # List
Tuple (tuple) – Ordered but unchangeable collection.
colors = ("Red", "Green", "Blue") # Tuple
3. Set Types
Used for storing unique values.
Set (set) – Unordered collection with unique elements.
numbers = {1, 2, 3, 3, 4} # Set (duplicates removed)
Ans:-
Compares each bit of two numbers and returns 1 if both bits are 1, otherwise
returns 0.
Example:
a = 5 # Binary: 0101
b = 3 # Binary: 0011
2. Bitwise OR (|)
Compares each bit of two numbers and returns 1 if at least one bit is 1,
otherwise returns 0.
Example:
a = 5 # Binary: 0101
b = 3 # Binary: 0011
print(result) # Output: 7
Compares each bit of two numbers and returns 1 if the bits are different,
otherwise returns 0.
Example:
a = 5 # Binary: 0101
b = 3 # Binary: 0011
print(result) # Output: 6
Example:
a = 5 # Binary: 0101
Ans:-
numbers = [1, 2, 3]
a = [1, 2, 3]
b=a