Python interpreter? :/


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

This code:

pi = 3.14
print str(pi)

Is suposed to print the integer 3.14 in console. In codecademy does, but in my IDLE of Python 3.6.2 does not. Can anyone explain me…? Please :slight_smile:


#2

Have you ensured your python version is the same as codecademy? If it isn’t, you can’t just go copy pasting code and expect it to work


#3

But I don’t know what is the version of codecademy Python. Which is it?


#4

have you googled: find python version or something similair? If you do, you find this:

which yields us code:

import sys
print(sys.version)

we can use to find the python version, surely this will run in a lesson to find codecademy’s python version


#5

Yes, I’m using Python 3.6.2. I used:

import sys
print(sys.version)

in codecademy so it said the version is 2.7.12, so now it’s understandable.
Anyways, Python 2 is not the same as Python 3. There is no course for Python 3?


#6

not the same i wouldn’t say, but at the release of python3 the decision was made to make python3 not backward-compatible with python2. So yes, there are differences, but they still are the same language

if we google:

python2 vs python3 differences

we find this article:

like i was trying to show you already in previous answer, there is a lot you can find by googling


#7

xD
Okey, thanks for everything, I should google the things next time :slight_smile:


#8

Of course we are here on the forum to help, but being capable of a simple google search is a must for a developer. And never take for granted that two environments are the same.


#9

You should use python3.

Not to defend codecademy, but most of the differences between 2 and 3 aren’t brought up in the course. Whenever something doesn’t “work”, you ought to be googling for how to do that something. This will probably just be print statement vs function and that division always produces a float in python3

Another thing is that codecademy uses an old way of formatting strings (with the modulo operator) - in newer code you should be using str.format or in 3.6 and later prefix with an f instead:

name = 'bob'

# old:
'hello %s' % name
# new:
'hello {}'.format(name)
# 3.6+
f'hello {name}'

#10

@ionatan makes a valid point, for new projects always use python3 if possible


#11

I’ve already seen that most fo the differences are of the kind:

Python2:

pi = 3.14
print str(pi)

-> 3.14

Python3:

pi = 3.14
print (str(pi))

-> 3.14

So is not that difficult.


#12

well, some of the difference are more significant:

print range(5) # outputs: [0, 1, 2, 3, 4]

while in python3:

print(range(5))

range produces a range object, so, there are some significant differences. raw_input() vs input(), also an important one.

Yet this changes might seem small, but in a large program, it might be difficult to oversee


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.