Statements and Identifiers
Explore important Python statements such as import, assert, break, and continue to control program flow and behavior. Understand the rules and conventions for naming identifiers, including how to imply privacy in classes. This lesson equips you with essential knowledge to write clearer and more effective Python code.
We'll cover the following...
We'll cover the following...
Description of some Python statements
This section describes the Python statements we have not covered so far, or that have more options than have previously been covered. Let’s take a look at them:
1. import statement:
import modulewill import all the names from the specifiedmodule, but every use of a name must be prefixed bymoduleand a dot (.). This is to prevent problems when the same name is imported from more than one module.from module import nameswill import the given names, which do not need to be prefixed bymoduleand a dot (.). Ifnamesis replaced by an asterisk (*), that means to import all names.import module as namewill import all the names frommodule, but every use of a name must be prefixed bynameand a dot (.).from module import name1 as name2importsname1but renames it toname2.
2. assert expression1, expression2
- Does nothing if
expression1is true, but it raises anAssertExceptionifexpression1is