What does '->' in function definition/declaration stmt in python means? [duplicate] - python

This question already has answers here:
What does -> mean in Python function definitions?
(11 answers)
What are type hints in Python 3.5?
(5 answers)
Closed 9 months ago.
The function I saw has a "->int" sign after the declaration statement.
class Solution:
def numUniqueEmails(self, emails: List[str]) -> int:
What does it mean? And how can it be used or the best practices to follow?
Thanks in advance.

Related

Understanding the Python.org help files [duplicate]

This question already has answers here:
What is the meaning of a forward slash "/" in a Python method signature, as shown by help(foo)? [duplicate]
(1 answer)
Bare asterisk in function parameters?
(6 answers)
What does the slash mean when help() is listing method signatures?
(3 answers)
Closed 16 days ago.
Pythonestas,
I can't find any guidance or explanation of the Python help documentation?
As an example, what does the "*" and the "/" refer to?
If the default value for key = None, where are the explanations for what can be used for the key argument?
sorted(iterable, /, *, key=None, reverse=False)ΒΆ
Thanks in advance!
Cannot find the answer in the Python.org docs.

What is the ':' in a python assignment statement? [duplicate]

This question already has answers here:
What are type hints in Python 3.5?
(5 answers)
Closed 6 years ago.
What does the colon on words_pron_dict:str mean? I am getting syntax error on python 2.7. Is it python 3? How can i use it?
class TextToSpeech:
CHUNK = 1024
def __init__(self, words_pron_dict:str = 'cmudict-0.7b.txt'):
self._l = {}
self._load_words(words_pron_dict)
It's a type annotation: https://docs.python.org/3/library/typing.html
You should be able to just remove it.

What is meaning of '#' operator? [duplicate]

This question already has answers here:
What is the '#=' symbol for in Python?
(3 answers)
What does the "at" (#) symbol do in Python?
(14 answers)
Closed 3 years ago.
I have come across this code and I have seen this unusual operation:
return Xtrain # eigenvectors[:2]
Does anyone know what it does?
Python documentation says:
Matrix Multiplication
Operator
a # b
Function
matmul(a, b)

Is it possible to create a statement in python? [duplicate]

This question already has answers here:
Can you add new statements to Python's syntax?
(13 answers)
Add new statements to Python without customizing the compiler
(2 answers)
Closed 4 years ago.
Can I create a statement in python 2.7?
Something similar to the print statement, that it's like a function, but gets the parameters without parenthesis.

Asterisk in Python 3 print function. What is it for? [duplicate]

This question already has answers here:
Asterisk in function call [duplicate]
(3 answers)
What does the asterisk do in Python other than multiplication and exponentiation? [duplicate]
(2 answers)
Closed 6 years ago.
Very Quick Question. I have a print function that looks like the statement below:
print(*Runner(x,y))
What is the * for in this case? I have no clue what it does in this context.

Categories