New course! Every coder should learn Generative AI!
Try a free lesson+ 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 ๐