TECHNICAL RESTRICTIONS :
![]() |
TECHNICAL RESTRICTIONS OR TECHNICAL ERRORS |
- variable starting with a number
imagine you are used variables names like 2names,user@site,and class in your code, but you keep getting errors upon execution. why because these are the keywords in the PYTHON language .
we see the technical restrictions and understand the restrictions. and also find the solutions of the restrictions .
variable starting with a number
CODE :
- 2names = "iron man" ------variable start with a number 2
- print(2names)
line 1 :
2names = "iron man"^^
variable name can have letters a to z , numbers 0 to 9 , and underscore _ . NO special characters or spaces are permitted in variable names.
<SYNTAX ERROR : invalid decimal literal
Initial variable rules
variables names should start with a letter either in lower case or in upper case or an underscore . numbers can be used later , but not as first character. so use two_names instead of 2names .
variable string with a alphabet characters
- two_names = "iron man"
- print(two_names)
output :
iron man ---desired output
- variables starting with special characters
variable name can have letters a to z , numbers 0 to 9 , and underscore _ . NO special characters or spaces are permitted in variable names. CODE :
user@site = "proinpythonlng.blogspot.com"
print(user@site)
output :
line 1
user@site = "proinpythonlng.blogspot.com"
^^^^^^^^
Syntax error : cannot assign an expression here. may your mistake @
instead of this using user_site
The corrected code is
CODE :
user_site = "proinpythonlng.blogspot.com"
print(user_site)
output :
proinpythonlng.blogspot.com
- Safe variable naming
words like 'class' is a special keyword in python just like 'print' and should not be used as variable names . avoid using it to avoid errors
code :
class = "rolex"
print(class)
output :
class = "rolex"
^^^^^^^^^
syntax error : invalid syntax or bad input in line 1
learn using the it right way
instead of this using class_name
code :
class_name = "rolex"
print(class_name)
output :
rolex ----desired output
Avoiding common errors :
you assigned "squid game" to a variable called name. But when you print "Name", its showing error
code ;
name = "squid game"
print(Name)
output :
<Name error : name "Name" is not defined on line 2>
you must and should print as what you assigned as variable.
code :
first_name = "tony"
last_name = "stark"
print(first_name+" "+last_name)
output :
tony stark
- You have to must try in your python compiler use idle avoid online compilers to Errors
- Quiz about Arithmetic Operations In Python
0 Comments