Page 183 - AI_Ver_3.0_class_11
P. 183
• • Percentage Sign (%): Used in string formatting (old-style formatting).
• • Underscore (_): Used as a variable name, or in naming conventions, such as snake_case.
• • Hash (#): Used to create comments in Python code.
• • At Sign (@): Used in decorators.
• • Dollar Sign ($): Used in some Python libraries like pandas for referencing columns in data frames.
• • Tilde (~): Used as the complement operator in bitwise operations.
• • Double Underscore (__): Used in special methods (dunder/magic methods) and sometimes for name mangling in
classes.
• • Angle Brackets (< and >): Used for comparison operations.
• • Vertical Bar or Pipe (|): Used in bitwise OR operations.
• • Ampersand (&): Used in bitwise AND operations.
• • Caret (^): Used in bitwise XOR operations.
• • Double Period (..): Used in some libraries and frameworks for specifying ranges or intervals.
• • Ellipsis (...): Used as a placeholder in some contexts, such as in NumPy arrays or as part of type hints.
• • Minus-Equivalent (-=): Used in augmented assignment statements.
• • Double Greater Than (>>) and Double Less Than (<<): Used in bit shifting operations.
Variables
In Python, variables are used to store and manipulate data values. Variables in Python do not have fixed locations in
memory. The memory location they refer to changes every time their values change.
Variable Assignment
Variables in Python are declared simply by assigning a value to them using the assignment operator (=).
Python syntax for assigning a value to a variable can be described as follows:
<Variable_name> = <value>
For example:
x = 10
name = "Yash"
my_list = [1, 2, 3, 4, 5]
Unlike some other programming languages, Python does not require explicit declaration of variables before they
are used. When a variable is assigned a value, Python automatically determines its data type based on the assigned
value. Python variables can hold values of various data types, including integers, floats, strings, booleans, lists, tuples,
dictionaries, and more.
For example:
# Integer variable
age = 30
# Float variable
pi = 3.14
# String variable
message = "Hello, World!"
# Boolean variable
is_student = True
Python Programming 181

