EvilZone
Programming and Scripting => Scripting Languages => : 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.
-
The problem is because you have typed
username = Joe
This 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
username = "Joe"
and username = 'Joe'
both are same things. ;)
Cheers!
parad0x
-
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?
-
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 doing0 = 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.
-
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.
-
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.
-
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