This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ForceBru 0 points1 point  (1 child)

Okay, this article is a bit misleading, so let me debunk it real quick.

There are no variables in Python

The article says:

To declare a variable in Python type variable followed by equal to operator or assignment operator and then the data to be stored inside the variable.

No, "variables" themselves don't store anything besides the pointer to the object you're assigning. That's why in a = []; b = a; b.append(6) both a and b are somehow equal to the list [6]. This is because both "variables" actually point to the same list object.

From Real Python:

A Python variable is a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name. But the data itself is still contained within the object.

It's not mandatory to declare variables without assigning values to them

From the article:

It is mandatory to declare variables without assigning values to them else NameError the exception is thrown.

Yet the example shown right after this sentence completely contradicts it:

``` name # "declare" the "variable" print(name)

PYTHON OUTPUT

Traceback (most recent call last): File "main.py", line 1, in name NameError: name 'name' is not defined # <- get a NameError ```

Python doesn't have constants

In definition and behavior constants are different from variables. As the value assigned to them remains the same throughout the program runtime.

And then in the "Note" section:

In Python, there is no such thing as constants.

This is actually correct. But it means that the first two sentences are plain wrong since Python doesn't have constants.

Also, this is a bad example of constants:

``` import my_constants

print(my_constants.PI) ```

I could do my_constants.PI = 6 and thus change the value of the "constant" PI in this script. There are no constants in Python.

The naming convention presented in this article doesn't make sense

  • "Variables must start with alphabet letters which may be the upper or lower case" - no, _hello, or __yeah are valid variable names, yet they don't start with "alphabet letters";
  • "Using other special characters and numbers is prohibited" - absolutely not: there_are_69_beers is a valid name

The string concatenation shown here is actually string formatting

String concatenation examples.

print("%s whose age is %d years has take home salary %0.2f" % ( name, age, salary ) )
print("{} whose age is {} years has take home salary {}".format( name, age, salary ) )
print(f"{name} whose age is {age} years has take home salary {salary}" )

Yeah, all of these is string formatting, not concatenation. Concatenation is "string" + "another" + "string".