Think of variable like:-
a storage for a single item storage.
you can store 1 / value in a variable.
eg
name= "Dfocmaru"
here you can assume name is the box and "Dfocmaru" is the item
there are certain conditions for variable to be a variable
first of all
it should not be in str: ""
"" cause if its in quotation it automatically becomes string
a= "d4" is correct
"a"="d4" is incorrect
the 2nd condition is:- you can't start variable name with numbers or symbols (#$%^&*)
any special symbols ain't working
1N="D4" is wrong
but
N1="D4" is correct
@N="ZEN" is wrong
N@="ZEN" is also wrong
3rd condition:- Underscore (_) is an exception:
_name="dfocmaru" is correct
name_2="d4" is also correct
HOPE YOU ALL Understand
Now we all are gonna go to type conversion
Type Conversion is just changing type of variable.
lets say
when user types the input its usally in string format.
with type conversion you can change the string to int and so on but. the input has to respect the boundaries of each datatypes.
You cannot just change
a="HELLO WORLD"
to
print(int(a))
thats a recipe for disaster
what youc an do it
if
a="123"
to
print (int(a))
this will change to integar.
but whats the point of this?
Its simple really
lets say in basic math
when user gives input its usally in string
so when you ask using inpu
a=input("Put a number here") user typed:- 69
This basically saying "69" which is a string
so you can't say
print (a+67). it will give type error
however
print(int(a)+67) is valid
and you can't add string with an integar
so we use type conversion.
Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.
YOU ARE READING
PYTHON JOURNEY BY BEGINNER
FanfictionWELCOME TO DFOCMARU'S JOURNEY Where codes become madness, brains go senseless, nights turn restless, eyes grow shineless, spines go spineless, and hands... well, they're boneless. This is Python Journey by Beginner - a chaotic diary of bugs, coffee...
