title: Python: How to use type function in if statements?
body: <p>I'm writing a program that loads a list of data from a file and I need the program to differentiate if the data in the line is either a string or an integer. However in the code I have done the program doesn't differentiate numbers from strings.</p>
  
  <p>An example of the list of data I have:</p>
  
  <pre><code>HAJOS
  ALFRED
  1896
  1
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>def medalsYear():
    times = 1
    totalGold = 0
    totalSilver = 0
    totalBronze = 0
    while times &lt;= 5:
      alpha = fob.readline() #reads file line by line#
      print(alpha)
      times = times + 1
      if type(alpha) == int:
          if alpha == 1:
              totalGold = totalGold + 1
              print("gold medal won")
          elif alpha == 2:
              totalSilver = totalSilver + 1
              print("silver medal won")
          elif alpha == 3:
              totalBronze = totalBronze + 1
              print("bronze medal won")
          else:
              pass
      else:
          print('is a string')
    print(totalGold, "Gold medals won")
    print(totalSilver, "Silver medals won")
    print(totalBronze, "Bronze medals won")
  </code></pre>
  
  <p>My problem is that when the program reads a line that has an integer, it doesn't determine correctly if the line contains an integer and from there run through the corresponding if statement. Currently my output looks like this.</p>
  
  <pre><code>HAJOS
  is a string
  ALFRED
  is a string
  1896
  is a string
  1
  is a string
  
  is a string
  0 Gold medals won
  0 Silver medals won
  0 Bronze medals won
  done
  </code></pre>