In the wild, these animals will defend themselves if they feel threatened. It’s just a natural response.
In captivity, yes, they are very capable of affection (to the degree they are capable of as reptiles) and never underestimate their intelligence. People make the mistake of falling for the reptilian brain crap. The problem with that is the studies done were flawed by doing a direct structural comparison between mammalian and reptilian brains. That is currently being debunked through new studies and behavioral experiments.
I cannot stand that “reptilian brain” stuff, particularly when it comes to brain size being the presumed determining factor. Pseudoscience at its worst.