write() only takes a single string argument, so you could do this:

outf.write(str(num))

or

outf.write('{}'.format(num))  # more "modern"
outf.write('%d' % num)        # deprecated mostly

Also note that write will not append a newline to your output so if you need it you'll have to supply it yourself.

Aside:

Using string formatting would give you more control over your output, so for instance you could write (both of these are equivalent):

num = 7
outf.write('{:03d}\n'.format(num))

num = 12
outf.write('%03d\n' % num)          

to get three spaces, with leading zeros for your integer value followed by a newline:

007
012

format() will be around for a long while, so it's worth learning/knowing.

Answer from Levon on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_numbers.asp
Python Numbers
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. ... x = 1 y = 35656222554887711 z = -3255522 print(type(x)) print(type(y)) print(type(z)) Try it Yourself ยป ยท Float, or "floating point number" ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ int
Python int() (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... The int() function converts a number or a string to its equivalent integer.
Discussions

python - How to write integer values to a file using out.write()? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
how to set a value to be an integer?
If you want to check if an integer is divisible, you would use remainder division and check if the rest equals zero. This is done using the modulo operator %: if beta % 4 == 0: More on reddit.com
๐ŸŒ r/learnpython
9
5
October 21, 2023
Is there a way to make input() accept strings and integers?
Instead of casting input straight into an integer you can wait and check if it's done first. Instead of: grade = int(input("Enter grade: ")) Do this: grade = input("Enter grade: ") if grade.lower() == 'done': print("Done.") else: integer_grade = int(grade) More on reddit.com
๐ŸŒ r/learnpython
6
3
October 8, 2021
How to convert a users input into an integer
Method 1 Use a list. A list is a data type that collects together other objects in a sequence. Each item is assigned an index indicating its location: the first item is at index 0, the second at index 1, etc. colors = ["black", "red", "blue", "white"] # accessing a color from a number print(colors[0]) # prints "black" # accessing a number from a color print(colors.index("black")) # prints 0 Method 2 Use a dictionary. A dictionary is a data type made up of key-value pairs. You access the values through the keys. For example, colors = {"black": 0, "red": 1, "blue": 2, "white": 3} # accessing a number from a color print(colors["black"]) # prints 0 Now, one problem with dictionaries is that they're good at looking up values from keys but not the other way around. You can do it, though -- one way would be like this: # accessing a color from a number for color, index in colors.items(): if index == 0: break print(color) # prints "black" Method 3 This one may be a little complicated for someone on their first day (and I really just mention it for fun), but you could use a list of named tuples. A named tuple is like a regular tuple except that you assign names to each of the positions in addition to indices. Note that you have to import namedtuple from the collections module and you have to set up the named tuple template before you can use it. from collections import namedtuple Color = namedtuple("Color", ["color", "number"]) colors = [Color("black", 0), Color("red", 1), Color("blue", 2), Color("white", 3)] # accessing a color from an index for color in colors: if color.number == 0: break print(color.color) # prints "black" # accessing a number from a color for color in colors: if color.color == "black": break print(color.number) # prints 0 This might look the most complicated (and it is), but it's also the most flexible of the options and the most symmetric in terms of treating the number and color name on equal footing. That said, named tuples are still tuples and thus you can use an index if you like. So this would actually be the faster way of getting the color from the number. print(color[0]) # prints "black" More on reddit.com
๐ŸŒ r/learnpython
8
32
June 10, 2022
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ python โ€บ python-number-type
Python Numbers: int, float, complex (With Examples)
... #integer variables x = 0 print(x) x = 100 print(x) x = -10 print(x) x = 1234567890 print(x) x = 5000000000000000000000000000000000000000000000000000000 print(x) ... Integers can be binary, octal, and hexadecimal values.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_int.asp
Python int() Function
Built-in Modules Random Module ... Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The int() function converts the specified value into an integer number. ... If you want to ......
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-int-function
Python int() Function - GeeksforGeeks
September 26, 2025 - The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part. Example: In this example, we passed a string as an argument to the int() function ...
Find elsewhere
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_numbers.htm
Python - Numbers
To convert a Hexadecimal string to integer, set the base to 16 in the int() function. ... Try out the following code snippet. It takes a Hexadecimal string, and returns the integer. num_string = "A1" number = int(num_string, 16) print ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ introduction.html
3. An Informal Introduction to Python โ€” Python 3.14.3 documentation
The interpreter acts as a simple calculator: you can type an expression into it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / can be used to perform arithmetic; parentheses (()) can be used for grouping. For example: >>> 2 + 2 4 >>> 50 - 5*6 20 >>> (50 - 5*6) / 4 5.0 >>> 8 / 5 # division always returns a floating-point number 1.6 ยท The integer numbers (e.g.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-represent-an-integer-in-Python
How to represent an integer in Python - Quora
Python represents integers using a variable-length format. Internally, it uses a structure that includes a reference count and a type identifier, along with a value stored in a contiguous block of memory.
๐ŸŒ
Real Python
realpython.com โ€บ python-numbers
Numbers in Python โ€“ Real Python
April 1, 2023 - For example, the following converts ... In Python, you canโ€™t use commas to group digits in integer literals, but you can use underscores (_)....
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-17202.html
Writing integer to file
April 2, 2019 - I open a file for appending: file = open(filename, "a")I have a numeric CurrentCount=300This prints 300 print (CurrentCount)This outputs a lot of digits, obviously not decoded into ASCII file.write(st
๐ŸŒ
Pierian Training
pieriantraining.com โ€บ home โ€บ python tutorial: how to take an integer input in python
Python Tutorial: How to take an integer input in Python - Pierian Training
April 12, 2023 - We then use the `int()` function to convert the string to an integer and store it in a variable called `num`. Finally, we print out the value of `num` using the `print()` function. Note that if the user enters a non-integer value (such as a string or float), then Python will raise a ValueError.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-take-integer-input-in-python
How to take integer input in Python? - GeeksforGeeks
July 26, 2024 - So for taking integer input we have to type cast those inputs into integers by using Python built-in int() function.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to print an integer in python
How to print an integer in Python | Replit
1 month ago - In this example, the integer 42 is assigned to the variable number. When you pass this variable to the print() function, Python automatically converts the integer into a string representation that can be displayed on the screen.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ int() function in python
int() Function in Python - Scaler Topics
June 29, 2024 - We can convert any string into an integer using the built-in python method called int() method. The int() method takes a string or integer data type and converts the given data into an integer number.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python-int-function.htm
Python int() Function
We create the "numeric_part" variable using a list comprehension that filters out non-numeric characters, resulting in a string with only digits "42". Finally, we use the int() function to convert this string into an integer โˆ’
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ c-api โ€บ long.html
Integer Objects โ€” Python 3.14.3 documentation
February 24, 2026 - On success, allocate *digits and return a writer. On error, set an exception and return NULL. negative is 1 if the number is negative, or 0 otherwise. ndigits is the number of digits in the digits array. It must be greater than 0. ... After a successful call to this function, the caller should fill in the array of digits digits and then call PyLongWriter_Finish() to get a Python int.
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 02-numbers โ€บ 01-integers
Integers :: Introduction to Python
June 27, 2024 - In Python, we can store an integer value in a variable using an assignment statement: ... That statement will store the integer value $ 5 $ in the variable x. Notice that the value $ 5 $ does not have quotation marks around it. This is because we want to store the integer value $ 5 $ and not ...