Python Exercise
The Python programming language has a small, formal, and rigid syntax.
- Identifiers are descriptive labels that identify a piece of data or a definition. Identifiers help developers organize their thoughts by giving items meaningful labels. A meaningful identifier is easier to remember. We access Python data and definitions with their identifier.
- Keywords are English words that have special meaning in the language.
- Statements are analogous to an English sentence. They are grammatically correct sequences of symbols, values, and words.
- Code blocks group statements together in related chunks.
- Whitespace is very important in Python syntax. If we alter whitespace, it changes the meaning of the code.
- Comments are messages embedded in the code so developers can read them, but are ignored by the interpreter.
Identifiers
- Class identifiers should be
camelCase.
- Variable and function identifiers should be
snake_case.
- We should never use unpredictable identifiers like
ThIsNaMeIsVaLiDbUtCoNfUsInG. Identifiers should be meaningful and predictable.
- No single character identifiers.
A docstring
"""Prints a message to standard output.
If `name` exists, prints it prefixed with "Hello".
If it doesn't, reverses a "Hello world!" string.
Parameters:
name (string): an optional name of a person
Returns:
Nothing
"""
Multi-line comments
# This is a multi-line comment.
# Don't need to run these.
# We can wait.
# say_hello("")
# say_hello("Touger")
Single-line comments
# check if the name is None or empty