Post AUmKdgIHPIdoBxKgi0 by cyrillep@mastouille.fr
(DIR) More posts by cyrillep@mastouille.fr
(DIR) Post #AUmFLNngvWBNquTrBg by calculsoberic@mstdn.social
2023-04-18T13:03:51Z
0 likes, 0 repeats
specifying the data type of a variable in #Python - x = str(3)y = int(3)z = float(3)print(x)print(y)print(z)Result: 333.0#coding #Programming
(DIR) Post #AUmHsWyY2CzFlzUbHE by chemoelectric@masto.ai
2023-04-18T13:29:51Z
0 likes, 0 repeats
@calculsoberic To be pedantic :))))))))))))) : That’s really specifying the type of a value. The variable can still hold any type. It would be the same even if you removed variables from Python. (See Otus Lisp for an example of that.)
(DIR) Post #AUmHsXlp50P0EoXx56 by calculsoberic@mstdn.social
2023-04-18T13:32:15Z
0 likes, 0 repeats
@chemoelectric oh, ok. I'm just taking these online coding classes and sharing the lessons here, so...blame them? :flan_laugh:
(DIR) Post #AUmINCukfi5MX0LQQK by chemoelectric@masto.ai
2023-04-18T13:37:47Z
0 likes, 0 repeats
@calculsoberic Yup, I blame them! :DDDDDDIt’s a subtle thing that goes away in daily conversation, where one uses terms such as ‘variable’ much more loosely than when being pedantic. (For instance, calling the binding of a name to a value a ‘variable’ in a language such as Standard ML, even though you cannot assign to it. To get an actual variable in that language, you have to jump through a hoop. Or use an array. :) )
(DIR) Post #AUmIWNu3BYc9DbOOpM by calculsoberic@mstdn.social
2023-04-18T13:39:27Z
0 likes, 0 repeats
@chemoelectric here's the lesson, if that helps: https://www.w3schools.com/python/trypython.asp?filename=demo_variables_casting - I suspect they were simplifying it for people unfamiliar with the terms, but that's just my guess. I have taken Python courses before, and I'm doing this as a refresher.
(DIR) Post #AUmIcwn2ODpx9iF2u0 by chemoelectric@masto.ai
2023-04-18T13:39:35Z
0 likes, 0 repeats
@calculsoberic It does matter in this respect: People may tell you Python doesn’t have strong typing but it’s just not so. They are confusing having typed variables with having typed values. Languages such as C have the former as well as the latter.
(DIR) Post #AUmIcxy40iFcoCPMjA by calculsoberic@mstdn.social
2023-04-18T13:40:38Z
0 likes, 0 repeats
@chemoelectric If you really feel ruffled by it, I suppose we could contact them and ask them to change it or clarify? :nkoShrug:
(DIR) Post #AUmIumKvzeWTwpbDeK by tshirtman@mas.to
2023-04-18T13:43:49Z
0 likes, 0 repeats
@calculsoberic not to be pedant but this does not define the type of the variable, just the value, and the value has a type. But if you set the variable to a different value later, it can have a different type.
(DIR) Post #AUmIyE2vQVGwkworI0 by chemoelectric@masto.ai
2023-04-18T13:44:26Z
0 likes, 1 repeats
@calculsoberic No, I’m just being a smart alec. :)
(DIR) Post #AUmJBHX1mL2rKa7p1k by calculsoberic@mstdn.social
2023-04-18T13:46:51Z
0 likes, 0 repeats
@chemoelectric Maybe I'll ask them about it. They have a contact form.
(DIR) Post #AUmJZo9CAMjVR7flY0 by chemoelectric@masto.ai
2023-04-18T13:51:16Z
0 likes, 0 repeats
@calculsoberic I suppose. When I tried to be pedantic with Python folk over some of their documentation, though, it didn’t go well. :)
(DIR) Post #AUmJjmJ9rLuIcz5RsO by calculsoberic@mstdn.social
2023-04-18T13:53:05Z
0 likes, 0 repeats
@chemoelectric I contacted them and asked if they could specify the difference on their lessons. Hope I don't get an angry email back! :flan_laugh:
(DIR) Post #AUmJkNHKP7QbI1W0f2 by chemoelectric@masto.ai
2023-04-18T13:52:09Z
0 likes, 1 repeats
@calculsoberic For instance I objected about them calling something O(n) when it was actually O(1) because n had a strict limit. :)
(DIR) Post #AUmK8Rr32eWMQrhbTk by chemoelectric@masto.ai
2023-04-18T13:57:25Z
0 likes, 0 repeats
@calculsoberic Ideally they should find a way to rephrase. I just don’t like interacting with other programmers except university professors and such. Outside that circle of people who are just plain fascinated by programming, one sees a lot of unpleasantness these days. :)
(DIR) Post #AUmKTK2TIOWyH0zzw8 by cyrillep@mastouille.fr
2023-04-18T14:01:15Z
0 likes, 0 repeats
@calculsoberic it's nos specifying data type, it's conversion through constructor. You mostly never need that for leterals. For instance use `3.0` if you want to be sure to have a float.
(DIR) Post #AUmKVZHVay9O7u6TAm by calculsoberic@mstdn.social
2023-04-18T14:01:43Z
0 likes, 0 repeats
@cyrillep Maybe I should just delete the post, it wasn't me who called it that, OK?!
(DIR) Post #AUmKdgIHPIdoBxKgi0 by cyrillep@mastouille.fr
2023-04-18T14:03:10Z
0 likes, 0 repeats
@calculsoberic not a problem at all. Just wanted to precise things. No deletion required :-)
(DIR) Post #AUmM7eOT8VcWwM58zY by kirschwipfel@nerdculture.de
2023-04-18T14:19:29Z
0 likes, 0 repeats
To be even more pedantic:That’s not specifying the type of a value, but converting the integer 3 into different types.Speciating would simply be 3, ”3" (or '3’ or ”””3””" or '''3''') and 3.0@chemoelectric @calculsoberic
(DIR) Post #AUmM7fGLuAipdTIAym by calculsoberic@mstdn.social
2023-04-18T14:19:47Z
0 likes, 0 repeats
@kirschwipfel oh OK. @chemoelectric
(DIR) Post #AUmMAiJl0GkJylL41g by kirschwipfel@nerdculture.de
2023-04-18T14:20:02Z
0 likes, 0 repeats
To be even more pedantic:That’s not specifying the type of a value, but converting the integer 3 into different types.Speciating would simply be 3, ”3" (or '3’ or ”””3””" or '''3''') and 3.0@chemoelectric @calculsoberic
(DIR) Post #AUmMAituppfZmuFwO0 by calculsoberic@mstdn.social
2023-04-18T14:20:22Z
0 likes, 0 repeats
@kirschwipfel OK, OK I get it @chemoelectric
(DIR) Post #AUmMQLKIFhwDJ22ftQ by calculsoberic@mstdn.social
2023-04-18T14:23:11Z
0 likes, 0 repeats
@kirschwipfel why don't we all just write to them and tell them that the lesson is wrong :flan_laugh: @chemoelectric
(DIR) Post #AUmMow8J3dTgPTA8Qq by chemoelectric@masto.ai
2023-04-18T14:24:52Z
0 likes, 0 repeats
@kirschwipfel @calculsoberic I thought of that, but wasn’t going to be THAT pedantic. It is value returned by the expression as a whole that has the type of interest, after all. That you can get that value by different routes is not the topic at hand. :)
(DIR) Post #AUmMowgL16hS715JTc by calculsoberic@mstdn.social
2023-04-18T14:27:34Z
0 likes, 0 repeats
@chemoelectric Well, I can see I have a lot to learn :nerdcat: @kirschwipfel
(DIR) Post #AUmMzZcv4kX1nFYO8m by chemoelectric@masto.ai
2023-04-18T14:29:32Z
0 likes, 0 repeats
@calculsoberic @kirschwipfel Oh, but being really, really pedantic is way off topic. There is the question of equivalence, for instance. I believe that, in Scheme, if you have two copies of the integer 3, whether or not (eq? first-copy second-copy) is true is implementation dependent. :) You have to use a different form of equivalence than this most basic one, to test their equality.(I don’t think Python is anywhere specified such that ‘implementation dependent’ is a thing :) )
(DIR) Post #AUmNk1G8fdYSob2rTc by chemoelectric@masto.ai
2023-04-18T14:37:55Z
0 likes, 0 repeats
@calculsoberic @kirschwipfel I’m 60-something years old and have been coding (much more often as hobby than as schooling--not in Computer Science, mind you--or work) since I was 18.What this means is I have had a lot of time to be wrong about things, or to change my mind about them. :)(Unless they have changed things, FORTH is an example of a higher level language that has no strong typing. It was a great language for 8-bit microprocessors!)
(DIR) Post #AUmOGj6hBJ0G4aDxJY by chemoelectric@masto.ai
2023-04-18T14:41:42Z
0 likes, 1 repeats
@calculsoberic @kirschwipfel (Though it originated on 16-bit machines, I think. Doesn’t matter. Most 8-bit micros of the time had 16-bit address buses.)