Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Fully Functional

Dmitry Manasreh
Dmitry Manasreh
5,651 Points

How to call a function in python not in workspaces ?

I want to make and call functions but not in workspaces , how ?

3 Answers

A humble request. Learn to google. Read the docs at times. Googling properly is the most loyal friend of a developer. I'm sharing here a link to the google search.

https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20call%20a%20function%20in%20a%20different%20file%20python

Long ago, I had an issue with my keyboard. If i press J it used to display U, for I it used to display B, etc. I was wondering how would I even google this.. :)

as follows: def add (a,b): sum = a + b return sum

answer = add(4,5)

Dmitry Manasreh
Dmitry Manasreh
5,651 Points

I mean I have saved a function in a python file then how can i call this from another one ?

file1.py def add (a,b): sum = a + b return sum

file2.py import file1.py print(add(4,5))