+ 1
Python âType Conversionâ
Can someone please answer the following in regards to these two conversion examples: QC-1: >>>float(â300â + int(input(â4â))) I. How does python read this? II. What is the order in which python calculates this III. Whatâs the difference between: Int(â2â) + (â3â) and Int(â2â + â3â) ?
6 Answers
+ 3
float("300" + int(input("4")))
=>
step1. ask for input and show 4
step2. convert your input to int
step3. Error: "str" can't be added by "int"
int("2") + ("3")
=>
step1. convert str "2" to int 2
step2. Error: "int" can't be added by "str"
int("2" + "3")
=>
step1. "2" + "3" = "23"
step2. convert str "23" to int 23
step3. return int 23
+ 3
davy hermans really? let me try it
i seldom use tuple so I'm not suređ
***
ok, I've tried it, you're rightđ
+ 2
I agree with Flandre Scarlet but i think (correct me if i am wrong)
("3") would be a string
("3",) to make it a tuple
0
thanks guys I appreciate it! Flandre Scarlet and are we sure int(â2â) + int(â3) produces an error when both are the same?
0
Flandre Scarlet thank you đ