-1

Python3 allows some keywords to be assigned values (Which is bad according to my professor...)

For example:

>>> int = 10
>>> print(int)
10
>>> #But...
>>> print = 20
>>> print(print)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

But in C++:

#include<iostream>
int main(){
    int int=0; //yeah, this is absurd...
    printf("%d",int);
    return 0;
}

Output:

Hello.cpp: In function ‘int main()’:
Hello.cpp:3:9: error: expected unqualified-id before ‘=’ token
  int int=0;
         ^
Hello.cpp:4:14: error: expected primary-expression before ‘int’
  printf("%d",int);

Should not keywords be denied assignment of values in Python, like in C++?

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
  • 1
    why do you think that print is a keyword? https://www.programiz.com/python-programming/keywords-identifier why not try your test with an actual keyword and then see what happens? – UKMonkey Feb 21 '20 at 12:47

1 Answers1

1

Because Python is not C++.

  • From that you have some pros and some cons - its up to you to know and understand your use-case and use the language that's appropriate in your specific case.
  • No programming language will serve you as a silver bullet and solve all your problems and questions
Drako
  • 773
  • 10
  • 22