+ 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 ответов
+ 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 😊