I've recently bumped into string methods and mainly
str()
method caught my interest because, it makes string out of every type of data? integers, booleans and so on. And if you want, they can be easily stored in variables like new strings:
my_string = str(45161516)
that variable will automatically hold that number as a string and same with the boolean:
my_string = str(True)
but, when you put pure word "dog" for example:
my_string = str(dog)
variable won't hold it as a string... Here's also an image when I was trying out this concept during my Python course:
Can I ask why is it so?
Why the variable doesn't return value and why
str(dog)
doesn't make a string "dog"?
Is it because "dog" in no datatype so the method doesn't recognize it?
Or it's just way it is and don't poke the beehive. At first I thought that variables can't hold string methods but it turned out that
my_variable = str(pure word)
is the only case when variable doesn't hold and return anything.
dog
doesn't exist until you set it to something.