Knowledgebase

Variables and Assigning Values Print

  • python, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Storing things.

WHAT A VARIABLE IS

A name referring to a value.

HOW IT WORKS

You assign a value to a name, then use the name.

WHAT PYTHON DOES DIFFERENTLY FROM SOME LANGUAGES

You do not declare a type.

The name simply refers to whatever you assigned.

WHAT THAT MEANS

A name can refer to a number, then later to text.

Possible, and usually a sign of confused code.

HOW TO NAME VARIABLES

Descriptively, in lowercase, with underscores between words.

WHY NAMING MATTERS

Code is read far more often than it is written.

A name explaining its purpose removes the need for a comment.

WHAT TO AVOID

Single letters, except for short loops Names that mislead Names differing only in case Reusing the same name for different purposes

WHAT NOT TO NAME THINGS

Anything matching a built-in name, which then becomes unavailable.

WHAT CONSTANTS LOOK LIKE

Names in capitals, by convention.

Python does not enforce it; the convention signals intent.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot