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.

28th Apr 2018, 12:30 PM
Parsix3
Parsix3 - avatar
8 ответов
+ 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.
28th Apr 2018, 12:47 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
+ 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.
28th Apr 2018, 12:56 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
0
Yes, thanks
28th Apr 2018, 1:02 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
0
Thank you
28th Apr 2018, 1:03 PM
Parsix3
Parsix3 - avatar
- 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?
28th Apr 2018, 12:45 PM
Parsix3
Parsix3 - avatar
- 1
ok, if I write: foo = input(lasagne) foo = int(input(lasagne)) it works?
28th Apr 2018, 12:54 PM
Parsix3
Parsix3 - avatar
- 1
Only number. Ok. int(input(2)) _________ x = 5 del x x = 2 or >>> x = 5 >>> x = 2 Correct?
28th Apr 2018, 1:01 PM
Parsix3
Parsix3 - avatar