Python Language - 03

 

Variables

    In Python, a variable is a named container for storing values. Variables can be assigned values using the assignment operator '='. For example:

In this example, the variables 'x', 'y', and 'z' are created and assigned values. 'x' is assigned the value '2', 'y' is assigned the value '3', and 'z' is assigned the value of 'x + y', which is '5'. There are a few rules to keep in mind when naming variables in Python:

  1. Variable names can only contain letters, numbers, and underscores. They cannot start with a number.
  2. Variable names should not be the same as Python keywords or built-in functions.
  3. Variable names should be descriptive, but not too long.
  4. Variable names should use snake case, not CamelCase or Pascal Case.

It's also important to note that in Python, variables are dynamically typed, which means that you can assign a value of any type to a variable, and then later assign a value of a different type to the same variable. For example:




Post a Comment

0 Comments