mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 18:24:39 +02:00
Modules
This commit is contained in:
@@ -563,29 +563,27 @@ Clovek.odkaslej_si() # => "*ehm*"
|
|||||||
## 6. Moduly
|
## 6. Moduly
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
# You can import modules
|
# Lze importovat moduly
|
||||||
import math
|
import math
|
||||||
print(math.sqrt(16)) # => 4
|
print(math.sqrt(16)) # => 4
|
||||||
|
|
||||||
# You can get specific functions from a module
|
# Lze také importovat pouze vybrané funkce z modulu
|
||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
print(ceil(3.7)) # => 4.0
|
print(ceil(3.7)) # => 4.0
|
||||||
print(floor(3.7)) # => 3.0
|
print(floor(3.7)) # => 3.0
|
||||||
|
|
||||||
# You can import all functions from a module.
|
# Můžete také importovat všechny funkce z modulu, ale radši to nedělejte
|
||||||
# Warning: this is not recommended
|
|
||||||
from math import *
|
from math import *
|
||||||
|
|
||||||
# You can shorten module names
|
# Můžete si přejmenovat modul při jeho importu
|
||||||
import math as m
|
import math as m
|
||||||
math.sqrt(16) == m.sqrt(16) # => True
|
math.sqrt(16) == m.sqrt(16) # => True
|
||||||
|
|
||||||
# Python modules are just ordinary python files. You
|
# Modul v Pythonu není nic jiného, než obyčejný soubor .py
|
||||||
# can write your own, and import them. The name of the
|
# Můžete si napsat vlastní a prostě ho importovat podle jména
|
||||||
# module is the same as the name of the file.
|
from muj_modul import moje_funkce # Nyní vyhodí ImportError - muj_modul neexistuje
|
||||||
|
|
||||||
# You can find out which functions and attributes
|
# Funkcí dir() lze zjistit, co modul obsahuje
|
||||||
# defines a module.
|
|
||||||
import math
|
import math
|
||||||
dir(math)
|
dir(math)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user