Programming - PYTHON Python - https://www.python.org/

Variables II

In this video you saw that the following two are equivalent in terms of assignment: x = 3 y = 4 z = 5 and x, y, z = 3, 4, 5 However, the above isn’t a great way to assign variables in most cases, because our variable names should be descriptive of the values they hold. Besides writing variable names that are descriptive, there are a few things to watch out for when naming variables in Python.

  1. Only use ordinary letters, numbers and underscores in your variable names. They can’t have spaces, and need to start with a letter or underscore.
  2. You can’t use reserved words or built-in identifiers that have important purposes in Python, which you’ll learn about throughout this course. A list of python reserved words is described here. Creating names that are descriptive of the values often will help you avoid using any of these words. A quick table of these words is also available below. (image/png)3. The pythonic way to name variables is to use all lowercase letters and underscores to separate words. YES my_height = 58 my_lat = 40 my_long = 105 NO my height = 58 MYLONG = 40 MyLat = 105 Though the last two of these would work in python, they are not pythonic ways to name variables. The way we name variables is called snake case, because we tend to connect the words with underscores.

Tags: programming


Date
February 9, 2024