I don't know why didn't get the type print. The print type keeps coming out as str.Please help me[enter image description here](https://i.stack.imgur.com/FPrUW.jpg)
CodePudding user response:
Looking at your code, you have defined my_variable
twice on lines 1 and 18. My understanding is that you only need to have the print statement on line 21, so line 18 (and lines 19 - 20 too) should probably be removed.
The comments indicate that before the code is executed, the value of my_variable
will be changed to test for different possible data types, so that's all you need to do.
Here is an example to understand datatypes:
print(type("Hello, world!")
gives you:
<class 'str'>
str
corresponds to a 'string' datatype. You can learn more about them here.
print(type(3.4)
gives you:
<class 'float'>
while
print(type(3)
gives you:
<class 'int'>
but:
print(type(3.0))
gives
<class = 'float'>
int
is for integers and float
is for float, learn more here.
Moreover,
print(type(False))
or
print(type(True))
gives:
<class 'bool'>
bool
stands for boolean, which can only have values True
or False
.
Hope this helps.
CodePudding user response:
There is no specific type "print" the output of the type() is the Datatype of the variable. Learn more about it here ([Python type() Function][1] [1]: https://www.w3schools.com/python/ref_func_type.asp
CodePudding user response:
- Please do NOT post code as image, it is very uncomfortable
- Please give more context in the future :)
Answer:
You do not need to put my_variable = "Hello, world!"
second time after the big comment, because as far as I can see, the program will only edit the first line and check if type of my_variable
is correct.