EvilZone

Programming and Scripting => Scripting Languages => : IntelAnon August 04, 2013, 05:53:59 AM

: Python run-time error.
: IntelAnon August 04, 2013, 05:53:59 AM
This is my first computer language and I am going through my first tutorial.

print("Hello")
username = Joe
print(username)

Why won't Python assign "Joe" as the output ( I guess that's how i'll put it ) to the variable "username"?

Correct ANYTHING (use of words and my actual problem)

Thanks.
: Re: Python run-time error.
: parad0x August 04, 2013, 06:19:31 AM
The problem is because you have typed
:
username = JoeThis makes python think that Joe is a variable, not a string constant. If you want to think python it as a string, do
:
username = "Joe"
You can use single quotes instead of double quotes. That's a matter of choice. Look here
: (Python)
username = "Joe" and
: (Python)
username = 'Joe'both are same things. ;)

Cheers!
parad0x
: Re: Python run-time error.
: IntelAnon August 04, 2013, 06:25:08 AM
Okay, thank you very much. I guess I was confused from the progress of the tutorial. It starts with explaining in mathematics and logic, where the tutorial would not have you put quotes around say 1.
For example,
>>> username="joe"
>>> un=1
>>> print(username)
joe
>>> print(un)
1
>>>

Any further explanations, please?
: Re: Python run-time error.
: parad0x August 04, 2013, 06:27:52 AM
Yes, all the numbers are constants, you cannot change them.
Therefore
:
un = 1 is right but
:
username = Joe is wrong until Joe is a variable or constant.

Try doing
:
0 = 1 and you'll see an error saying "cannot assign value to literal".

Constants and variables are written without the quotes whereas strings and characters are written using quotes.
: Re: Python run-time error.
: IntelAnon August 04, 2013, 06:45:59 AM
Okay thank you parad0x, I'll be sure to go over what you just stated tomorrow. It is almost 1am. This is more then likely causing my fog. On a "brighter" note, I am thoroughly enjoying learning this language! I don't know exactly what I plan on doing with it, or what I can do with it. Even though I know a little about computers and have done challenges, I still consider myself very new.
 
: Re: Python run-time error.
: parad0x August 04, 2013, 06:57:22 AM
Okay thank you parad0x, I'll be sure to go over what you just stated tomorrow. It is almost 1am. This is more then likely causing my fog. On a "brighter" note, I am thoroughly enjoying learning this language! I don't know exactly what I plan on doing with it, or what I can do with it. Even though I know a little about computers and have done challenges, I still consider myself very new.
Python is an excellent scripting language to automate various tasks. It has powerful libraries, easy to use syntax. So basically, you can use python from automating your tasks to make hacking tools to automate hacking for you.


Python is worth learning.Have fun with python.
: Re: Python run-time error.
: RedBullAddicted August 04, 2013, 10:34:03 AM
Nice parad0x :) Just a little addition to what you already explained

:
>>> number = 1
>>> type(number)
<type 'int'>
>>> number = "1"
>>> type(number)
<type 'str'>
>>> username = "joe"
>>> type(username)
<type 'str'>
>>> print(username)
joe
>>> joe = "evilzone"
>>> username = joe
>>> print(username)
evilzone

Hope this helps

Cheers,
RBA