1.Python module.
Python a. py suffix file, called a module. A python module can contain variables, functions, classes, and variables and functions that can be defined in a class.
2.Python module Import.
(1) All Python module Import mode: From Module name import *
(2) Python module on-demand Import mode: From Module name Import function name/class name
3. function. Common functions are as follows.
STR (o): Converts a number to a string function,
Int (o): Converts a string into a numeric function.
Format (): String formatting function.
Replace: string substitution function.
Input: Enter the function.
he.py Code:
#Coding=utf-8defPlus1 (num1,num2): Num=num1+num2returnNumdefMinus1 (num1,num2): Num=num1+num2returnNumclassHe:def __init__(self):Pass defPlus2 (self,num1,num2): Num=num1+num2returnNumdefMinus2 (self,num1,num2): Num=num1+num2returnNum
Calling code:
Python 3.6.1 (V3.6.1:69C0DB5, Mar, 17:54:52) [MSC v.1900 32bit (Intel)] on Win32type"Copyright","credits" or "license ()" forMore information.>>> fromHeImport*>>> Num=plus1 (20,15)>>>Print(num)35>>> fromHeImportPlus1>>> Num=plus1 (20,15)>>>Print(num)35>>> fromHeImportHe>>> he=He ()>>> Num=he.plus2 (20,15)>>>Print(num)35>>> num2=25>>>Print("num2:"+str (num2)) num2:25>>> age="2">>>Print(int (age))2>>> str="Uid:{0},uname:{1}">>> Str=str.format ("1","Joyet")>>>Print(str) UID:1, Uname:joyet
>>> str2= "Joyet55"
>>> Str2=str2.replace ("55", "66")
>>> Print (STR2)
Joyet66
>>> a=input ("Please Enter:")
Please enter: 45
>>> Print (a)
45
Python basic knowledge of functions, modules