Python Forum
Need help converting string to int
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help converting string to int
#3
(Jul-07-2021, 03:57 PM)deanhystad Wrote: int(num * num * num) does the operation inside the the parenthesis before converting to int. You can do this:
print((int(num)**3)
# or
num = int(num)
print(num * num * num)


Oh ok i understand. But 1 question. First try i did this i for example put 3 to cube, and it splitted them into 333333333 instead of 27, why?
num = input("Enter a number to CUBE: ")
result = int(num)


def cube():
    print(int(num * int(num) * int(num)))


cube()
Reply


Messages In This Thread
Need help converting string to int - by dedesssse - Jul-07-2021, 03:48 PM
RE: Need help converting string to int - by dedesssse - Jul-07-2021, 04:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting DateTime string and and converting it from AM/PM to 24 hours tester_V 2 1,082 Jun-08-2024, 05:16 PM
Last Post: tester_V
  Converting '1a2b3c' string to Dictionary PythonNoobLvl1 6 3,262 May-13-2022, 03:44 PM
Last Post: deanhystad
  Beautify dictionary without converting to string. sharoon 6 4,606 Apr-11-2021, 08:32 AM
Last Post: buran
  how to deal with problem of converting string to int usthbstar 1 2,592 Jan-05-2021, 01:33 PM
Last Post: perfringo
  Converting string to hex triplet menator01 4 6,415 Aug-03-2020, 01:00 PM
Last Post: deanhystad
  converting string object inside a list into an intiger bwdu 4 3,511 Mar-31-2020, 10:36 AM
Last Post: buran
  Converting query string as a condition for filter data. shah_entrance 1 2,395 Jan-14-2020, 09:22 AM
Last Post: perfringo
  Converting a patterned string or text into excel table soup1987 1 2,649 Oct-03-2019, 01:37 AM
Last Post: Larz60+
  converting array to and from string in python 3.7.2 srm 5 7,840 Jul-03-2019, 01:11 PM
Last Post: snippsat
  Trouble converting JSON String to Dictionary RBeck22 7 8,465 Mar-28-2019, 12:12 PM
Last Post: RBeck22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020