Le1 Language Basics Ending - Jupyter Notebook
Le1 Language Basics Ending - Jupyter Notebook
There certain rules we must keep in mind when picking a name for our variables, functions, classes,
modules, etc we create in Python. The most important of those rules are as follows:
1. Identifiers in Python can contain numbers (0-9), alphabets (uppercase and lowercase), and underscore
(_). These are the only characters allowed.
2. Identifiers cannot start with a number
3. Identifiers should not contain only numeric characters
4. Identifiers are case-sensitive: Number_1 is not equivalent to number_1
5. Identifiers can begin with an underscore. But this is generally only a good practice for certain instances.
Identifiers that start with single underscore or double underscore bear a special meaning in the
language.
6. Using the name of a builtin function and keywords as an identifier are invalid in some cases and should
be avoided. Some reserved keywords include:
In [1]:
# Invalid identifiers
1st_number = 20
In [ ]:
In [ ]:
--------------------------------------------------------------------
-------
NameError Traceback (most recent cal
l last)
/tmp/ipykernel_9202/316428408.py in <module>
1 # Identifiers are case-sensitive
2 Number1 = 50
----> 3 print(number1) # Number1 != number1
In [ ]:
12
--------------------------------------------------------------------
-------
TypeError Traceback (most recent cal
l last)
/tmp/ipykernel_9202/3912415968.py in <module>
8 # Attempting the same thing throws an error:
9 another_decimal = 3.142
---> 10 new_number = int(another_decimal)
1. Variables and function (discussed later in the course) should be lowercase, with words separated by
underscores as necessary to improve readability. This naming convention is referred to as snake_case.
2. It is not recommended to use single letter l (el) or letter I as identifiers because it can be unclear
which is which in certain font styles.
3. Modules names (Python files) should have short, all-lowercase names. Underscores can be used in the
module name if it improves readability. Python packages (folders containing python files) should also
be short, all-lowercase names, although the use of underscore is discouraged.
You can read the full style guide here: PEP 8: Style Guide for Python Code (https://peps.python.org/pep-
0008)
In [ ]:
In [ ]:
In [ ]: