Python Fundamentals ā Operators & Strings
Variables
Definition
Variables are named memory locations used to store data.
Syntax
name = "Tejas"
age = 24
salary = 50000
Key Points
- No need to declare data type.
- Python determines type automatically.
- Variables are case-sensitive.
Interview Point
Python is a dynamically typed language.
Integer (int)
Definition
Stores whole numbers without decimal values.
Example
num = 100
print(type(num))
Output:
<class 'int'>
Interview Point
Integers in Python can store very large values without overflow issues seen in some languages.
Arithmetic Operators
Definition
Used to perform mathematical calculations.
| Operator | Description |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| // | Floor Division |
| % | Modulo |
| ** | Power |
Example
a = 20
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** b)
Key Observations
20 / 3 = 6.666...
20 // 3 = 6
20 % 3 = 2
20 ** 3 = 8000
Interview Point
/ always returns float.
Comparison Operators
Definition
Used to compare two values.
Operators
<
>
<=
>=
==
!=
Example
a = 10
b = 20
print(a < b)
print(a >= b)
print(a == b)
print(a != b)
Output
True
False
False
True
Interview Point
Comparison operators always return Boolean values.
Logical Operators
Definition
Used to combine multiple conditions.
Operators
and
or
not
Example
age = 25
salary = 50000
print(age > 18 and salary > 30000)
print(age > 30 or salary > 30000)
print(not(age > 30))
Interview Point
Python uses short-circuit evaluation.
Membership Operators
Definition
Checks whether a value exists inside a sequence.
Operators
in
not in
Example
text = "DevOps"
print("Ops" in text)
print("AWS" not in text)
Interview Point
Frequently used while searching logs and validating inputs.
Identity Operators
Definition
Compare memory locations of objects.
Operators
is
is not
Example
a = [1, 2]
b = [1, 2]
print(a == b)
print(a is b)
Output
True
False
Interview Point
== compares values.
is compares object identity.
Bitwise Operators
Definition
Perform operations on binary values.
Operators
&
|
^
~
<<
>>
Example
a = 5
b = 3
print(a & b)
print(a | b)
print(a ^ b)
print(~a)
Interview Point
Important in networking, permissions, and low-level system operations.
Strings
Definition
A sequence of characters enclosed within quotes.
Example
name = "DevOps"
print(name)
print(type(name))
Key Points
- Strings are immutable.
- Can use single, double, or triple quotes.
- Supports indexing and slicing.
Interview Point
Strings cannot be modified in place because they are immutable.
Quick Revision
# Arithmetic
+ - * / // % **
# Comparison
< > <= >= == !=
# Logical
and or not
# Membership
in not in
# Identity
is is not
# Bitwise
& | ^ ~ << >>
Class Summary
This class covered Python data representation, arithmetic operations, comparisons, logical evaluation, object identity, bitwise operations, and strings. These concepts form the foundation for automation scripts, infrastructure tooling, API integrations, and cloud engineering workflows.
Top comments (0)