dynamic-typing

Can someone tell me what Strong typing and weak typing means and which one is better?

瘦欲@ 提交于 2019-11-28 17:12:42
Can someone tell me what Strong typing and weak typing means and which one is better? That'll be the theory answers taken care of, but the practice side seems to have been neglected... Strong-typing means that you can't use one type of variable where another is expected (or have restrictions to doing so). Weak-typing means you can mix different types. In PHP for example, you can mix numbers and strings and PHP won't complain because it is a weakly-typed language. $message = "You are visitor number ".$count; If it was strongly typed, you'd have to convert $count from an integer to a string,

Do union types actually exist in python?

时光怂恿深爱的人放手 提交于 2019-11-28 11:13:31
Since python is dynamically typed, of course we can do something like this: def f(x): return 2 if x else "s" But is the way python was actually intended to be used? or in other words, do union types exist in the sense they do in racket for example? Or do we only use them like this: def f(x): if x: return "x" where the only "union" we need is with None? Union typing is only needed when you have a statically typed language, as you need to declare that an object can return one of multiple types (in your case an int or str , or in the other example str or NoneType ). Python deals in objects only,

How to deal with Python ~ static typing? [closed]

早过忘川 提交于 2019-11-28 00:09:11
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago . I am from Java world and I wonder what is so great about dynamic typing in Python besides missing errors while compiling the code? Do

How can I type-check variables in Python?

六月ゝ 毕业季﹏ 提交于 2019-11-27 17:08:16
问题 I have a Python function that takes a numeric argument that must be an integer in order for it behave correctly. What is the preferred way of verifying this in Python? My first reaction is to do something like this: def isInteger(n): return int(n) == n But I can't help thinking that this is 1) expensive 2) ugly and 3) subject to the tender mercies of machine epsilon. Does Python provide any native means of type checking variables? Or is this considered to be a violation of the language's

Can someone tell me what Strong typing and weak typing means and which one is better?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 10:16:37
问题 Can someone tell me what Strong typing and weak typing means and which one is better? 回答1: That'll be the theory answers taken care of, but the practice side seems to have been neglected... Strong-typing means that you can't use one type of variable where another is expected (or have restrictions to doing so). Weak-typing means you can mix different types. In PHP for example, you can mix numbers and strings and PHP won't complain because it is a weakly-typed language. $message = "You are

Understanding PHP Type Coercion

给你一囗甜甜゛ 提交于 2019-11-27 05:20:39
I saw this small piece of code that is evading my understanding: <?php $a = '0e462097431906509019562988736854'; $b = '0e830400451993494058024219903391'; var_dump($a == $b); Which will output: bool(true) I understand that when using == PHP will attempt fuzzy comparison, silently converting between types in order to perform the comparison. What I'm not understanding is why PHP seems to think these two strings are the same. I would have thought since $a and $b are strings, that no type conversion would need to take place. What am I not understanding? I think this article explains it pretty well:

Understanding PHP Type Coercion

不想你离开。 提交于 2019-11-26 12:47:26
问题 I saw this small piece of code that is evading my understanding: <?php $a = \'0e462097431906509019562988736854\'; $b = \'0e830400451993494058024219903391\'; var_dump($a == $b); Which will output: bool(true) I understand that when using == PHP will attempt fuzzy comparison, silently converting between types in order to perform the comparison. What I\'m not understanding is why PHP seems to think these two strings are the same. I would have thought since $a and $b are strings, that no type

Static/Dynamic vs Strong/Weak

混江龙づ霸主 提交于 2019-11-26 11:57:45
I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I'm aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can't find somewhere that talks about both and actually spells out the difference. What would be nice is if someone could please spell this out clearly here for me and the rest

Static/Dynamic vs Strong/Weak

两盒软妹~` 提交于 2019-11-26 02:25:52
问题 I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I\'m aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can\'t find somewhere that talks about both and actually spells out the

What is the difference between statically typed and dynamically typed languages?

我是研究僧i 提交于 2019-11-25 22:29:15
问题 I hear a lot that new programming languages are dynamically typed but what does it actually mean when we say a language is dynamically typed vs. statically typed? 回答1: Statically typed languages A language is statically typed if the type of a variable is known at compile time. For some languages this means that you as the programmer must specify what type each variable is (e.g.: Java, C, C++); other languages offer some form of type inference , the capability of the type system to deduce the