VARIABLES
VARIABLES
In Python, variables are used to store data values. They serve as named references or placeholders for values that can be used and manipulated within a program. Here's an overview of variables in Python:
Variable Naming:
A variable name can consist of letters (both uppercase and lowercase), digits, and underscores. However, it must start with a letter or an underscore. Python is case-sensitive, so variables named "myVariable" and "myvariable" would be considered different.
Variable Assignment
Variables are created and assigned values using the assignment operator (=). For example:
x = 10 name = "John"
- Numeric types: int (integer), float (floating-point number), complex (complex number)
- Strings: str (sequence of characters)
- Boolean: bool (True or False)
- Collections: list, tuple, set, dictionary
Variable Reassignment:
Variables can be reassigned with new values of the same or different data types. The type of a variable can change when reassigned to a value of a different type.
Variable Naming Conventions
It's good practice to follow naming conventions to write clean and readable code. Variable names should be descriptive and meaningful. For example, age
instead of a
, total_students
instead of t_s
, etc. Python follows the PEP 8 style guide for naming conventions.
Constants:
Comments
Post a Comment