Friday, November 21, 2025
HomeLanguagesPython | Numpy np.can_cast() method

Python | Numpy np.can_cast() method

With the help of np.can_cast() method, we can get the perfect idea that one data type can be able to cast into another data type or not by using np.can_cast() method.

Syntax : np.can_cast(source data_type, target data_type)
Return : Return the boolean value as true when casting can be done else false.

Example #1 :
In this example we can see that by using np.can_cast() method, we are able to get the boolean value as true when casting can be performed else false by using this method.




# import numpy
import numpy as np
  
# using np.can_cast() method
gfg = np.can_cast(np.int32, np.int64)
  
print(gfg)


Output :

True

Example #2 :




# import numpy
import numpy as np
  
# using np.can_cast() method
gfg = np.can_cast(5.5e10, np.int32)
  
print(gfg)


Output :

False

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS