How to split integer and assigning parts to variablesSplitting integer in Python?Getting only element from a single-element list in Python?How do I check whether a file exists without exceptions?How do JavaScript closures work?How do I generate random integers within a specific range in Java?How do I parse a string to a float or int?Using global variables in a functionHow do you check if a variable is an array in JavaScript?How do I pass a variable by reference?“Least Astonishment” and the Mutable Default ArgumentConvert a string to an integer?How to determine if variable is 'undefined' or 'null'?

Global variables and information security

Which costing factors go into the optimizer choosing different types of spools?

What is the source of the fear in the Hallow spell's extra Fear effect?

What is the majority of the UK Government as of 2019-09-04?

Entering the US with dual citizenship but US passport is long expired?

How does the UK House of Commons think they can prolong the deadline of Brexit?

Is the interior of a Bag of Holding actually an extradimensional space?

Shoes for commuting

Why are all volatile liquids combustible

Left my gmail logged in when I was fired

What is the difference between 「名前【なまえ】」 and 「名称【めいしょう】」?

Are buttons really enough to bound validities by S4.2?

In-universe, why does Doc Brown program the time machine to go to 1955?

Is the Levitate spell supposed to basically disable a melee-based enemy?

Tiny image scraper for xkcd.com

Is there any reason to change the ISO manually?

If I sell my PS4 game disc and buy a digital version, can I still access my saved game?

split a six digits number column into separated columns with one digit

Who are these people in this satirical cartoon of the Congress of Verona?

Why does the seven segment display have decimal point at the right?

MOSFET broke after attaching capacitor bank

Tying double knot of garbarge bag

Vimscript - Surround word under cursor with quotes

A Meal fit for a King



How to split integer and assigning parts to variables


Splitting integer in Python?Getting only element from a single-element list in Python?How do I check whether a file exists without exceptions?How do JavaScript closures work?How do I generate random integers within a specific range in Java?How do I parse a string to a float or int?Using global variables in a functionHow do you check if a variable is an array in JavaScript?How do I pass a variable by reference?“Least Astonishment” and the Mutable Default ArgumentConvert a string to an integer?How to determine if variable is 'undefined' or 'null'?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have been recently working on code that is a calculator. I know calculations can be done in the shell but that's no fun. Anyway, I have successfully been able to separate the numbers from the equation so that I can add them together. However it outputs like so:



Numbers: 22



This happens with the equation 2+2.



What I want to happen is it to take this integer (22) and separate it into 2 and 2 then assign those to variables "num1" and "num2" so that I can add them.



I have already tried:



[int(i) for i in str(Numbers)]


But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.



I have looked at this:
Splitting integer in Python?



That is what got me my output above. I have also looked at this:
Getting only element from a single-element list in Python?



But I didn't understand that and don't have a high enough reputation score to comment and ask for explanation.



This is my current code as it currently stands:



var = input("Type equation:")

if " + " in var:
nums = str(re.findall(r'd',var))
nums2 = nums.replace("['", "")
nums3 = nums2.replace("', '", "")
Numbers = nums3.replace("']", "")
print(Numbers)









share|improve this question


























  • FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

    – iz_
    Mar 28 at 4:19












  • What is your input, your output and expected output?

    – Saurav Sahu
    Mar 28 at 4:21

















1















I have been recently working on code that is a calculator. I know calculations can be done in the shell but that's no fun. Anyway, I have successfully been able to separate the numbers from the equation so that I can add them together. However it outputs like so:



Numbers: 22



This happens with the equation 2+2.



What I want to happen is it to take this integer (22) and separate it into 2 and 2 then assign those to variables "num1" and "num2" so that I can add them.



I have already tried:



[int(i) for i in str(Numbers)]


But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.



I have looked at this:
Splitting integer in Python?



That is what got me my output above. I have also looked at this:
Getting only element from a single-element list in Python?



But I didn't understand that and don't have a high enough reputation score to comment and ask for explanation.



This is my current code as it currently stands:



var = input("Type equation:")

if " + " in var:
nums = str(re.findall(r'd',var))
nums2 = nums.replace("['", "")
nums3 = nums2.replace("', '", "")
Numbers = nums3.replace("']", "")
print(Numbers)









share|improve this question


























  • FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

    – iz_
    Mar 28 at 4:19












  • What is your input, your output and expected output?

    – Saurav Sahu
    Mar 28 at 4:21













1












1








1








I have been recently working on code that is a calculator. I know calculations can be done in the shell but that's no fun. Anyway, I have successfully been able to separate the numbers from the equation so that I can add them together. However it outputs like so:



Numbers: 22



This happens with the equation 2+2.



What I want to happen is it to take this integer (22) and separate it into 2 and 2 then assign those to variables "num1" and "num2" so that I can add them.



I have already tried:



[int(i) for i in str(Numbers)]


But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.



I have looked at this:
Splitting integer in Python?



That is what got me my output above. I have also looked at this:
Getting only element from a single-element list in Python?



But I didn't understand that and don't have a high enough reputation score to comment and ask for explanation.



This is my current code as it currently stands:



var = input("Type equation:")

if " + " in var:
nums = str(re.findall(r'd',var))
nums2 = nums.replace("['", "")
nums3 = nums2.replace("', '", "")
Numbers = nums3.replace("']", "")
print(Numbers)









share|improve this question
















I have been recently working on code that is a calculator. I know calculations can be done in the shell but that's no fun. Anyway, I have successfully been able to separate the numbers from the equation so that I can add them together. However it outputs like so:



Numbers: 22



This happens with the equation 2+2.



What I want to happen is it to take this integer (22) and separate it into 2 and 2 then assign those to variables "num1" and "num2" so that I can add them.



I have already tried:



[int(i) for i in str(Numbers)]


But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.



I have looked at this:
Splitting integer in Python?



That is what got me my output above. I have also looked at this:
Getting only element from a single-element list in Python?



But I didn't understand that and don't have a high enough reputation score to comment and ask for explanation.



This is my current code as it currently stands:



var = input("Type equation:")

if " + " in var:
nums = str(re.findall(r'd',var))
nums2 = nums.replace("['", "")
nums3 = nums2.replace("', '", "")
Numbers = nums3.replace("']", "")
print(Numbers)






python variables integer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 4:14







Char Gamer

















asked Mar 28 at 4:09









Char GamerChar Gamer

105 bronze badges




105 bronze badges















  • FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

    – iz_
    Mar 28 at 4:19












  • What is your input, your output and expected output?

    – Saurav Sahu
    Mar 28 at 4:21

















  • FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

    – iz_
    Mar 28 at 4:19












  • What is your input, your output and expected output?

    – Saurav Sahu
    Mar 28 at 4:21
















FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

– iz_
Mar 28 at 4:19






FYI, a dynamic number of variables is almost never a good idea. What's wrong with a list?

– iz_
Mar 28 at 4:19














What is your input, your output and expected output?

– Saurav Sahu
Mar 28 at 4:21





What is your input, your output and expected output?

– Saurav Sahu
Mar 28 at 4:21












2 Answers
2






active

oldest

votes


















1

















But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.




Use access through index:



num1, num2 = [int(i) for i in str(Numbers)] [0], [int(i) for i in str(Numbers)] [1] 





share|improve this answer

























  • This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

    – iz_
    Mar 28 at 4:21












  • Yes, to optimize that he can populate the list into a local variable and later access through index.

    – Saurav Sahu
    Mar 28 at 4:22












  • THANKS! This helped out so much! I got it working!

    – Char Gamer
    Mar 28 at 4:25











  • To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

    – iz_
    Mar 28 at 4:26


















1
















Assign your output to two variables num1, num2



num1,num2=list(str(Numbers))






share|improve this answer

























  • You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

    – iz_
    Mar 28 at 4:20













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390028%2fhow-to-split-integer-and-assigning-parts-to-variables%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1

















But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.




Use access through index:



num1, num2 = [int(i) for i in str(Numbers)] [0], [int(i) for i in str(Numbers)] [1] 





share|improve this answer

























  • This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

    – iz_
    Mar 28 at 4:21












  • Yes, to optimize that he can populate the list into a local variable and later access through index.

    – Saurav Sahu
    Mar 28 at 4:22












  • THANKS! This helped out so much! I got it working!

    – Char Gamer
    Mar 28 at 4:25











  • To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

    – iz_
    Mar 28 at 4:26















1

















But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.




Use access through index:



num1, num2 = [int(i) for i in str(Numbers)] [0], [int(i) for i in str(Numbers)] [1] 





share|improve this answer

























  • This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

    – iz_
    Mar 28 at 4:21












  • Yes, to optimize that he can populate the list into a local variable and later access through index.

    – Saurav Sahu
    Mar 28 at 4:22












  • THANKS! This helped out so much! I got it working!

    – Char Gamer
    Mar 28 at 4:25











  • To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

    – iz_
    Mar 28 at 4:26













1














1










1










But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.




Use access through index:



num1, num2 = [int(i) for i in str(Numbers)] [0], [int(i) for i in str(Numbers)] [1] 





share|improve this answer














But the output is in a list and I have not found anything about taking a list item and assigning it to a variable.




Use access through index:



num1, num2 = [int(i) for i in str(Numbers)] [0], [int(i) for i in str(Numbers)] [1] 






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 4:20









Saurav SahuSaurav Sahu

7,1843 gold badges30 silver badges47 bronze badges




7,1843 gold badges30 silver badges47 bronze badges















  • This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

    – iz_
    Mar 28 at 4:21












  • Yes, to optimize that he can populate the list into a local variable and later access through index.

    – Saurav Sahu
    Mar 28 at 4:22












  • THANKS! This helped out so much! I got it working!

    – Char Gamer
    Mar 28 at 4:25











  • To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

    – iz_
    Mar 28 at 4:26

















  • This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

    – iz_
    Mar 28 at 4:21












  • Yes, to optimize that he can populate the list into a local variable and later access through index.

    – Saurav Sahu
    Mar 28 at 4:22












  • THANKS! This helped out so much! I got it working!

    – Char Gamer
    Mar 28 at 4:25











  • To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

    – iz_
    Mar 28 at 4:26
















This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

– iz_
Mar 28 at 4:21






This redoes the same operation twice unnecessarily. Storing the result or using unpacking is a better idea.

– iz_
Mar 28 at 4:21














Yes, to optimize that he can populate the list into a local variable and later access through index.

– Saurav Sahu
Mar 28 at 4:22






Yes, to optimize that he can populate the list into a local variable and later access through index.

– Saurav Sahu
Mar 28 at 4:22














THANKS! This helped out so much! I got it working!

– Char Gamer
Mar 28 at 4:25





THANKS! This helped out so much! I got it working!

– Char Gamer
Mar 28 at 4:25













To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

– iz_
Mar 28 at 4:26





To simplify the code, simply do num1, num2 = (int(i) for i in str(Numbers)).

– iz_
Mar 28 at 4:26













1
















Assign your output to two variables num1, num2



num1,num2=list(str(Numbers))






share|improve this answer

























  • You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

    – iz_
    Mar 28 at 4:20















1
















Assign your output to two variables num1, num2



num1,num2=list(str(Numbers))






share|improve this answer

























  • You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

    – iz_
    Mar 28 at 4:20













1














1










1









Assign your output to two variables num1, num2



num1,num2=list(str(Numbers))






share|improve this answer













Assign your output to two variables num1, num2



num1,num2=list(str(Numbers))







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 4:15









SravanthiGSravanthiG

513 bronze badges




513 bronze badges















  • You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

    – iz_
    Mar 28 at 4:20

















  • You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

    – iz_
    Mar 28 at 4:20
















You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

– iz_
Mar 28 at 4:20





You don't need the list(str()), str() is enough, i.e. num1, num2 = str(Numbers). However, they will be strings, not integers.

– iz_
Mar 28 at 4:20

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390028%2fhow-to-split-integer-and-assigning-parts-to-variables%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh