Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
num = int(input("Enter the number"))
for i in range(1, 11):
     #print(str(num) + " X " + str(i) + "=" + str(i*num))

'''I understand the typecasting that on how we take user from input in form of int and we are converting in in str again but my doubt here is that how is it, we are performing the int type operation on str type things .One request please keep it in simple logic . I am just a beginner in coding and the above question is from a solution of a question tutorial I was watching online . if you have more than online logic please share that .. The question was to print a multiplication table in python using loop Thanks in advance '''

What I have tried:

I am not getting the logic on performing int type operation in python on str data type
Posted
Updated 24-Dec-22 3:55am
v6

1 solution

You have the following:
1. This is not typecasting, it is conversion. The int function takes a string of digits and converts it to an integer value.
2. Again, str is a function that takes a numeric value and converts it into a string of digits.
However in case 2 it is not necessary as the print function will automatically convert numerics to strings in order to display them correctly. Although you would need to modify the print statement to:
Python
print(num, " X ", i, "=", i * num)
 
Share this answer
 
Comments
CPallini 24-Dec-22 13:02pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900