syntax difference

Jim Lee jlee54 at gmail.com
Sun Jun 17 02:11:41 EDT 2018



On 06/16/2018 10:13 PM, Sharan Basappa wrote:
> I think I am now confused with format options in Python.
> I tried an example as below and both print proper value:
>
> age = 35
>
> print "age is %s" % age
> print "age is %d" % age
>
> %run "D:/Projects/Initiatives/machine learning/programs/six.py"
> age is 35
> age is 35
>
> I other languages I know the format specifier should be same as the variable type. For example, in the above case, it has to be %d and not %s

   Python is not like other languages.  For one thing, there are no 
"variables" in Python (in the way you think of them).   There are only 
objects and names.  Names can be thought of like void pointers in C, for 
example.  They don't have a "type" themselves - they only refer to 
objects, and the type of object they refer to can change at will.  Also, 
there are no integers in Python.  Scalar values are actually objects.  
The number 35 is not an integer, it is an object that has an integer 
type.  If you do a "dir(35)" in Python, you'll see that the object "35" 
has more than 70 methods associated with it.   I'll stop there to avoid 
information overload, but these are some of the key things a Python 
newcomer needs to wrap their head around....

-Jim




More information about the Python-list mailing list