Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples)

Python has come a long way since 2.7.
Back then:

print was still a statement
type hints didn’t exist

% formatting was the default

Today, we write functions very differently.

# Python 2.7
def greet(name):
print “Hello, %s” % name

#…


This content originally appeared on DEV Community and was authored by Sergey Kovalchuk

Python has come a long way since 2.7.
Back then:

  • print was still a statement
  • type hints didn’t exist
  • % formatting was the default

Today, we write functions very differently.

# Python 2.7
def greet(name):
    print "Hello, %s" % name
# Python 3.10+
def greet(name: str) -> str:
    return f"Hello, {name}"

And with Python 3.12, we even get more concise typing with list[str], | for unions, and better error messages.

In my full article, I walk through:

  • Type hints (from typing.List[str]list[str])
  • F-strings replacing % and .format()
  • Structural Pattern Matching (Python 3.10)
  • Why print had to change from statement → function

Read the full deep dive on Medium: Evolution of Functions in Python: From Python 2.7 to Today


This content originally appeared on DEV Community and was authored by Sergey Kovalchuk


Print Share Comment Cite Upload Translate Updates
APA

Sergey Kovalchuk | Sciencx (2025-08-27T09:10:11+00:00) Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples). Retrieved from https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/

MLA
" » Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples)." Sergey Kovalchuk | Sciencx - Wednesday August 27, 2025, https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/
HARVARD
Sergey Kovalchuk | Sciencx Wednesday August 27, 2025 » Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples)., viewed ,<https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/>
VANCOUVER
Sergey Kovalchuk | Sciencx - » Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/
CHICAGO
" » Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples)." Sergey Kovalchuk | Sciencx - Accessed . https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/
IEEE
" » Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples)." Sergey Kovalchuk | Sciencx [Online]. Available: https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/. [Accessed: ]
rf:citation
» Evolution of Python Functions: From 2.7 to 3.12 (with Code Examples) | Sergey Kovalchuk | Sciencx | https://www.scien.cx/2025/08/27/evolution-of-python-functions-from-2-7-to-3-12-with-code-examples/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.