What is / in python?

I'm wondering about / in python.

I know that it divides two integers, but I've seen something like this

'NAME': BASE_DIR / 'db.sqlite3' 
4

2 Answers

Python allows defining the behaviour of operators when applied to custom classes using specially named methods ("dunders", from "double-underline"), as described here. The / operator's behaviour can be defined by .__truediv__(self, other) method. It is almost certainly the case here that BASE_DIR is an instance of pathlib.Path, which defines / as semantically equivalent to os.path.join for strings. You can read more here.

0

BASE_DIR is pathlib.Path object which supports the / operator for joining paths. You need to either use / or use os.path.join if you use strings.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like