コード例 #1
0
subaru1 = Subaru()
subaru1.subaru_model("Subaru Forester")
subaru1.highest_speed("350km/hr")



# INHERITANCE

# use import to execute the code

import converter, numbersList

from converter import lbs_to_kg, calculator
from numbersList import max_number

print(lbs_to_kg(500))  # specific function import 

print(converter.kgs_to_lbs(100)) # unimported module 

print(calculator(10))  # specific function import 

numbers = [10,40,70,4,50] # input for numbers  Modules
print(max_number(numbers)) 




# THE TBELOW CODE GOED TO A NEW FILE AND IMPORT
# CREATE A NEW FILE AND ADD THE CODE BELOW AND USE IT IN THE ABOVE MAIN FILE TO IMPORT

# calculate the max in the list 
コード例 #2
0
from converter import lbs_to_kg
print(lbs_to_kg(50))
print(kg_to_lbs(50))
コード例 #3
0
"""
Created on Fri Apr 10 15:46:55 2020

@author: Ada
"""
# use module to organize codes
# refer to each file (containing related codes, classes, etc) as module

import converter
from converter import lbs_to_kg
from utils import find_max


print(converter.kg_to_lbs(70))

print(lbs_to_kg(120))

numbers = [4, 10, 6, 2]
print(find_max(numbers))

#a package : a folder for multiple modules

#Ex2
import ecommerce.shipping

ecommerce.shipping.calc_shipping()

#Ex3
from ecommerce.shipping import calc_shipping
#from ecommerce import shipping
コード例 #4
0
ファイル: module.py プロジェクト: sharmaronak79/python
#module is nothin but the creating some code and put in one other file and then
# call a function from that created file to current file
# here i have creatred some function of converters in conveter.py and imort them to my module file
# so it like header file we create in c language and include it in our surc code
#here the key words are used are import
import converter

converter.kg_to_lbs()
from converter import lbs_to_kg

lbs_to_kg()
s = [10, 55, 30, 70, 44]
from find_max import find_max

find_max(s)
import file

file.school()
file.college()
コード例 #5
0
class Dog(Mammal):
    # It means pass this line to interpreter
    pass


class Cat(Mammal):
    def be_annoying(self):
        print("ME U")


Mammal1 = Dog()
Mammal1.walk()

# use the imported file
print(converter.kg_to_lbs(50))

# use the imported method or class or ...
print(lbs_to_kg(450))

lists1 = [5, 4, 9, 7, 8, 5, 45, 0, 4]

print(find_max(lists1))

path = Path()
#path.mkdir()
#path.rmdir()

# (*.*) for file
for file in path.glob('*'):
    print(file)
コード例 #6
0
ファイル: modules.py プロジェクト: aiyeola/learn-python
import converter
#  or
from converter import lbs_to_kg, find_max

numbers = [10, 13, 2]
max = find_max(numbers)
print(max)

ans = converter.kg_to_lbs(22.5)
print(ans)

ann = lbs_to_kg(50)
print(ann)
コード例 #7
0
# Module: organize section in a Python file
import converter  # converter is a file into the folder
from converter import lbs_to_kg  # import a specific function from the selected file

print(lbs_to_kg(100))

print(converter.kg_to_lbs(70))

# Package: a bunch of modules
import ecommerce.shipping
# from ecommerce.shipping import calculate_shipping, calc_tax
# from ecommerce import shipping

ecommerce.shipping.calculate_shipping()

# Random
import random

for i in range(3):
    print(random.randint(10, 20))

members = ["Joe", "Avrel", "William"]
leader = random.choice(members)
print(leader)


# Working with directories
import path from Path

# Absolute path: from the hard drive comme :c\Program Files...
# Relative path: from a closer location
コード例 #8
0
import converter
import utils

print(converter.kg_to_lbs(120))
print(converter.lbs_to_kg(120))
numbers = [12, 3, 4, 5, 60, 78, 9]
max_num = utils.find_max(numbers)
print(max_num)