What is this()? [SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is this()? [SOLVED]

What does this() function do? Example: # from math import sqrt as this x = 4 y = 13 print(this(y - x)) Output: 3.0

13th Sep 2021, 8:05 AM
TriXioN
TriXioN - avatar
5 Answers
+ 6
TriXioN In Python ‘this’ is not a built-in method/function. You would simply write: print(y -x) The keyword ‘this’ and with Python more often ‘self’ is a naming convention used to refer to the current instance of a class object (usually specified as the first arg when defining a class). However ‘this’ in the context above has no meaning and would cause an error.
13th Sep 2021, 8:18 AM
DavX
DavX - avatar
+ 2
TriXioN You can put anything after 'as', in Python
14th Sep 2021, 5:52 PM
CGO!
CGO! - avatar
0
Ohh, sryy, im so potato, in answer i didnt see the line: Import sqrt from math as this, ohh my gosh, Im potato
13th Sep 2021, 3:51 PM
TriXioN
TriXioN - avatar
0
Haha, it happens 😎 From the sound of it you’ve worked it out, but to keep the question/answer correct. You are using ‘this’ as an alias for sqrt from math library. However, you’ve got the import statement the wrong way around: import sqrt from math as this Should be: from math import sqrt as this
13th Sep 2021, 4:37 PM
DavX
DavX - avatar
0
Bruh
13th Sep 2021, 4:58 PM
TriXioN
TriXioN - avatar