Statements and Identifiers
Learn about the different statements we have not yet covered and be introduced to the concept of identifiers in Python.
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.
Python 3.5
from math import sqrt # Importing math modulex = 16 # Assigning value to xsqrt_num = sqrt(x) # Using built-in sqrt functionprint(sqrt_num) # Displaying result
2. assert expression1, expression2
- Does nothing if
expression1is true, but it raises anAssertExceptionifexpression1is