0
Python variables
I have a problem to understand the last part of the variables. Can you explain me the error and del part? The lesson is not clear to me. I want to understand it very well and pass the exercise without doubts.
8 Réponses
+ 1
The variables foo and bar are called metasyntactic variables, meaning that they are used as placeholder names in example code to demonstrate something.
Metasyntactic Variable means they take only user input.
like-
foo = input() # user inputs are as String
foo = int(input())
To delete a variable you have to use "del" or you can change the variable value just readjusting it.
x = 7
del x # value of x is deleted
x= 3 # new value of x is 3
Or an alternate way
>>> x = 7
>>> x = 3
So you print x and you will get 3.
+ 1
int(input()) # only number converts into integer number
input() treats number as string, so we use int before it for treated them as integer.
0
Yes, thanks
0
Thank you
- 1
ok but I don't understand this part:
>>> foo = "a string"
>>> foo
'a string'
>>> bar
NameError: name 'bar' is not defined
>>> del foo
>>> foo
NameError: name 'foo' is not defined
Also, what is a foo?
- 1
ok, if I write:
foo = input(lasagne)
foo = int(input(lasagne))
it works?
- 1
Only number. Ok.
int(input(2))
_________
x = 5
del x
x = 2
or
>>> x = 5
>>> x = 2
Correct?