Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am wondering when you use the var: int and when to you use the int(var).

For example:

def func(var: int, var2):

    print(var - int(var2))

1 Answer

0 votes
by (36.8k points)

The var: int used to know the type of the variable that is expected to be and pass it to a desired function or class, while int(var) will cast var variable to be an instance of int class:

>> a = '3' # a is String

>> a = int(a)

>> a

out: 3 # a is Integer now

 Do check out python for data science certification to learn from scratch.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...