I used to code in C and Java a lot, so I thought that typing and defining variables in Python was fresh and interesting, and it was interesting that this made it more flexible, so I will explain it as far as I can understand. I will.
First, in C and Java, when creating a variable, define what type it is and assign the value that matches that type on the same line or another line, but in Python it is necessary to declare the type. All you have to do is substitute the value. Instead, you can't just declare the type, and when you create a new variable, you absolutely have to assign some value. Shiracamus explained the role of variables in Python in the comments, so please read that. A pointer in C language holds an address and accesses the value held by the address in memory, but I think that Pythond uses a dictionary for similar processing. In C language, you have to declare the type with a pointer, but it seems that Python is not necessary, and it seems that you can assign a value with another type to a variable that you have assigned something once, so you can reuse variables that you no longer need. Seems to be able to. Probably in the case of C language, the number of bits changes depending on the type, so it must be decided firmly, and since Python is designed so that there is no inconvenience in memory, it does not matter if you know the address. Python also has garbage collection so you can assign new values to existing variables and the values in the old addresses will be automatically discarded so you don't have to worry about memory. In C language, if you point the pointer to a different address, the original value will remain in the memory, which will be annoying when the memory capacity is exceeded. (I haven't developed it properly in C language, so I did half of it.)
As an aside, I'm a little curious about the divisor operator, so I'll mention it. If you calculate a number including a decimal with the operator'/' in Python 2.x, the numbers after the decimal point will not be truncated, but it seems that it can be truncated by using'//'. Also
python
from __future__ import division
It seems that if you calculate integers with'/' by importing, the result will be displayed even after the decimal point. It seems that this was planned to be installed as standard in Pyrhon 3.x, but if anyone knows, please let me know.
There may be misunderstandings or mistakes in what I wrote in this post, so if you notice anything, please let me know in the comments or email. I will edit it soon. Someone pointed out in the previous post, so don't hesitate to ask!
Reference: First Python 3rd Edition (Publisher: O'Reilly Japan)
Recommended Posts