Fundamentals 5 min read

Python print() Function Tutorial with PyCharm 2024.1 Local Code Completion

This article demonstrates how to use PyCharm 2024.1's local code line AI completion to explore the Python print() function, covering syntax, various output examples, file writing, custom separators, and common pitfalls, while providing complete code snippets for each case.

Top Architecture Tech Stack
Top Architecture Tech Stack
Top Architecture Tech Stack
Python print() Function Tutorial with PyCharm 2024.1 Local Code Completion

Hello everyone, welcome to the Top Architecture Tech Stack series; I am Xiao Er Ge. In this post I share my self‑learning journey of Python, focusing on the print() function.

PyCharm 2024.1 Local Code Completion

PyCharm 2024.1 introduces a new local code line AI completion feature. By typing a variable name, the IDE suggests the next line of code, such as completing a value of b after typing b and pressing Tab . Two types of suggestions are available: the new local line completion and the traditional dropdown suggestions.

print() Function Usage

The full syntax of print() is:

print(value,..., sep=' ', end='\n', file=None) where sep is the separator between multiple values, end specifies the line terminator, and file directs the output to a file.

Examples:

# Output a number
print(90)
a = 100  # variable a
b = 50   # variable b
# Output a variable
print(a)
# Output a calculation result
print(a*b)
# Output strings
print('hello world')
print("hello world")
print(''+'hello world'+'')
print(""+"hello world"+"")
# Output multiple items on one line
print("a+b=", a+b)
print("a*b=", a*b)
# Convert numbers to ASCII codes
print('a')
print(chr(97))
print('b')
print(chr(98))
# Output Unicode codes of Chinese characters
print(ord("程"))
print(ord("序"))
print(ord("视"))
print(ord("点"))
# Write data to a file
fp = open("note.txt", "w")
print("程序视点欢迎您!", file=fp)
fp.close()
# Customize line ending (default is \n)
print("程序视点", end="-->" )
print("欢迎您!")
# Concatenating string with number raises TypeError
print("程序视点欢迎您!" + 2024)  # TypeError

Conclusion

For learning Python programming, PyCharm is a friendly IDE. To obtain a stable and secure activation of PyCharm, follow the public account "程序视点" and reply with vip for more details. The article also mentions discounted JetBrains bundles, GitHub Copilot, and AI Assistant offers.

Pythoncode completiontutorialfundamentalsPyCharmprint()
Top Architecture Tech Stack
Written by

Top Architecture Tech Stack

Sharing Java and Python tech insights, with occasional practical development tool tips.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.