аватар question@mail.ru · 01.01.1970 03:00

How to divide the whole number into separate numbers, and bring them through a comma?

For example, there is a line a = 987

how to conclude in this format:?

   9 ,  8 ,  7      

it is possible like through a cycle for () and then write it to the list and display it through Split with a comma, but it will be a lot of code, as can be realized as well?

аватар answer@mail.ru · 01.01.1970 03:00

If you just need to get it out, then using:

  a =  987    str  (a), sep =  '', ')  #/\ the separator between the elements   #/\ bringing the number to the line   #/\ unpacking the line into separate symbols      

if the line '9,8,7' needs to be saved somewhere, then:

  A =  987  result =  '', ' .join ( str  (a))  ###### "" /\ We bring the number to the line   #/\ We sort out each symbol of the line   #/\ combine through a comma      
  
  
  
  
  
  
  
 , it is also possible Class = "">   print  (result)                                       

Latest

Similar