# Understand types of code?

**URL:** <https://forum.codewithmosh.com/t/understand-types-of-code/13633>\
**Category:** Python\
**Created:** [July 12, 2022, 3:20pm UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633 "2022-07-12T15:20:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![obay](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@obay](https://forum.codewithmosh.com/u/obay)\
**Post date:** [July 12, 2022, 3:20pm UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/1 "2022-07-12T15:20:55Z")

</div>

can someone explain how to deal with different types of codes and when the code is string or int or…

---

<div class="post-metadata">

**Author:** ![JohnLu](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JohnLu](https://forum.codewithmosh.com/u/JohnLu)\
**Post date:** [July 13, 2022, 4:08am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/2 "2022-07-13T04:08:33Z")

</div>

Care to elaborate? what do you mean ‘deal with’ ? and what’s your purpose in “dealing with” the different types? Something like multiplying a string with an int?

---

<div class="post-metadata">

**Author:** ![obay](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@obay](https://forum.codewithmosh.com/u/obay)\
**Post date:** [July 14, 2022, 8:59am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/3 "2022-07-14T08:59:11Z")

</div>

Shure I care  
i mean exactly what you said

---

<div class="post-metadata">

**Author:** ![JohnLu](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JohnLu](https://forum.codewithmosh.com/u/JohnLu)\
**Post date:** [July 14, 2022, 9:21am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/4 "2022-07-14T09:21:31Z")

</div>

Python language provides a built-in method to transfer string into int and float type or the other around. like this:

```auto
a_str = '12'
b_num = 3
result = int(a_str) * b_num
print(result)

```

---

<div class="post-metadata">

**Author:** ![obay](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@obay](https://forum.codewithmosh.com/u/obay)\
**Post date:** [July 14, 2022, 11:43am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/5 "2022-07-14T11:43:09Z")

</div>

can you go deeper in explaining?  
when should I use int() and when not?  
when the code is a string and when it’s int …?  
give me some examples, please  
thank you so much

---

<div class="post-metadata">

**Author:** ![JohnLu](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JohnLu](https://forum.codewithmosh.com/u/JohnLu)\
**Post date:** [July 14, 2022, 12:26pm UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/6 "2022-07-14T12:26:42Z")

</div>

In simple terms, you can only operate two same types of variables,otherwise, you should get an error report, I’ll show you some examples:

```auto
a = 1 # a number 
b = "0.5" # a string ,but can be transfered to a int number
c = '10' # a string ,but can be transfered to a float number
d = "not numeric" # pure string which cannot be transfered to a number

print(a + b) # this will report error message for I plus a int number with a string

print (b + c) # this output will be "0.510" instead of 10.5 because a string plus a string means concat, not add

print(a + int(c) ) # this output will be 11 because I use 'int()' method to transfer the string into a integer

print( a+ float(b) ) # this output will be 1.5 because I use 'float()' method to transfer the string into a float number

print( a + int(d) ) # this will report error message because you can never transfer the variable 'd' into a number

```

---

<div class="post-metadata">

**Author:** ![obay](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@obay](https://forum.codewithmosh.com/u/obay)\
**Post date:** [July 19, 2022, 8:11am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/7 "2022-07-19T08:11:23Z")

</div>

I get it  
this is so useful and helpful  
thank you so much for helping

---

<div class="post-metadata">

**Author:** ![JohnLu](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JohnLu](https://forum.codewithmosh.com/u/JohnLu)\
**Post date:** [July 20, 2022, 4:04am UTC](https://forum.codewithmosh.com/t/understand-types-of-code/13633/8 "2022-07-20T04:04:14Z")

</div>

Don’t mention it！I’m glad I can help.
