This question came up in my maths class. It is valid to use set notation and interval notation interchangeably where appropriate? For example could I define a function whose domain is a set and whose codomain is an interval?

i.e. $ $ f(x) : \mathbb{R} \rightarrow [0, 1]$ $

Similarly, can I use notation to exclude an interval from a set or vice versa: i.e. $ $ \mathbb{R }\setminus (0, 1]$ $

Thanks