Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Python

You're reading from   Learning Python Learn to code like a professional with Python - an open source, versatile, and powerful programming language

Arrow left icon
Product type Hardcover
Published in Oct 2021
Last Updated in Feb 2025
Publisher Packt
ISBN-13 9781801815093
Length 554 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Romano Romano
Author Profile Icon Romano
Romano
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. A Gentle Introduction to Python 2. Built-In Data Types FREE CHAPTER 3. Conditionals and Iteration 4. Functions, the Building Blocks of Code 5. Comprehensions and Generators 6. OOP, Decorators, and Iterators 7. Exceptions and Context Managers 8. Files and Data Persistence 9. Cryptography and Tokens 10. Testing 11. Debugging and Profiling 12. GUIs and Scripting 13. Data Science in Brief 14. Introduction to API Development 15. Packaging Python Applications 16. Other Books You May Enjoy
17. Index

Function attributes

Every function is a fully fledged object and, as such, it has many attributes. Some of them are special and can be used in an introspective way to inspect the function object at runtime. The following script is an example that shows a part of them and how to display their value for an example function:

# func.attributes.py
def multiplication(a, b=1):
    """Return a multiplied by b. """
    return a * b
if __name__ == "__main__":
    special_attributes = [
        "__doc__", "__name__", "__qualname__", "__module__",
        "__defaults__", "__code__", "__globals__", "__dict__",
        "__closure__", "__annotations__", "__kwdefaults__",
    ]
    for attribute in special_attributes:
        print(attribute, '->', getattr(multiplication, attribute))

We used the built-in getattr() function to get...

lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Python
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon