I feel as if I'm doing the code correctly and it comes out with an outcome but the outcome for the print function is being weird (I'm using Visual Studio Code on Kali Linux and I'm new).
My Code:
hello = "Hello this is"
print(hello, "code")
Outcome: ('Hello this is', 'code')
Are there any errors, because this code looks like it should be working fine.
you are printing two distinct items, the string in hello, and the literal 'code'
what you want (I think)
is:
print(f"{hello} code")
You are on linux so I expect you have both python2 and python3.
python
is associated with python2 version
I guess you are running this code with python2. Run it with python3. Use
python3
instead of just
python
.
$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print(hello, "code")
('Hello this is', 'code')
$ python3.7
Python 3.7.7 (default, Mar 10 2020, 17:25:08)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print(hello, "code")
Hello this is code
on python2 print is a statement, so you in fact you print a tuple
$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print hello, "code"
Hello this is code
python2 support ended, so use python3.
And as Larz suggested - it's better to use string formatting - f-strings or str.format() method
(May-08-2020, 03:50 AM)buran Wrote: [ -> ]You are on linux so I expect you have both python2 and python3. python
is associated with python2 version
I guess you are running this code with python2. Run it with python3. Use python3
instead of just python
.
$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print(hello, "code")
('Hello this is', 'code')
$ python3.7
Python 3.7.7 (default, Mar 10 2020, 17:25:08)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print(hello, "code")
Hello this is code
on python2 print is a statement, so you in fact you print a tuple
$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> hello = "Hello this is"
>>> print hello, "code"
Hello this is code
python2 support ended, so use python3.
And as Larz suggested - it's better to use string formatting - f-strings or str.format() method
I am using Visual Studio Code so i am unable to use the command python3
(May-07-2020, 10:07 PM)Zirizo Wrote: [ -> ]I feel as if I'm doing the code correctly and it comes out with an outcome but the outcome for the print function is being weird (I'm using Visual Studio Code on Kali Linux and I'm new).
My Code:
hello = "Hello this is"
print(hello, "code")
Outcome: ('Hello this is', 'code')
So, I figured out that when I press run on Visual Studio Code, Bash sends the command python -u "[file path]" now my Kali is set to automatically run python2, however I can override this by typing in python3 -u "[file path]" however I would not like to do this every single time. Is there a way for the python command to run straight python3?
follow Buran's post and change python version from within VCode.
Once you do this, the selected version will always be used when you press the run button and
also when you right click in code and select 'Run python file in terminal'