{"id":184,"date":"2026-09-03T09:03:30","date_gmt":"2026-09-03T09:03:30","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=184"},"modified":"2026-09-03T09:04:18","modified_gmt":"2026-09-03T09:04:18","slug":"write-a-python-program-to-define-class-book-with-attributes-booktitle-and-authorname","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2026\/09\/03\/write-a-python-program-to-define-class-book-with-attributes-booktitle-and-authorname\/","title":{"rendered":"WAP to define class Book with attributes BookTitle and AuthorName."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Write a Python program to define class Book with attributes BookTitle and AuthorName. Create two objects of the Book class with different titles and authors. Display the details (title and author) of both objects to show that their attribute values are independent.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Book:\n    def __init__(self, title, author):\n        \"\"\"\n        Constructor to initialize BookTitle and AuthorName.\n        \"\"\"\n        self.BookTitle = title\n        self.AuthorName = author\n\n    def display_details(self):\n        \"\"\"\n        Method to display the book's title and author.\n        \"\"\"\n        print(f\"Book Title: {self.BookTitle}\")\n        print(f\"Author: {self.AuthorName}\")\n        print(\"-\" * 20)\n\n# --- Creating two book objects (Indian Authors) ---\n\n# Object 1: A book by R.K. Narayan\nbook1 = Book(\"The Guide\", \"R.K. Narayan\")\nprint(\"Details of Book 1:\")\nbook1.display_details()\n\n# Object 2: A book by Arundhati Roy\nbook2 = Book(\"The God of Small Things\", \"Arundhati Roy\")\nprint(\"Details of Book 2:\")\nbook2.display_details()\n\n# Demonstrating that they are independent objects\nprint(\"--- Changing Book 1's Title ---\")\nbook1.BookTitle = \"Malgudi Days\"\nprint(\"Updated details of Book 1:\")\nbook1.display_details()\n\nprint(\"Details of Book 2 (Unchanged):\")\nbook2.display_details()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Write a Python program to define class Book with attributes BookTitle and AuthorName. Create two objects of the Book class with different titles and authors. Display the details (title and author) of both objects to show that their attribute values are independent. class Book: def __init__(self, title, author): &#8220;&#8221;&#8221; Constructor to initialize BookTitle and AuthorName. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":96,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,3],"tags":[53,52,25,26,45],"class_list":["post-184","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aiopd","category-bca","tag-aidpd","tag-aiopd","tag-bca","tag-bca-paper-solution","tag-python"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=184"}],"version-history":[{"count":3,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/184\/revisions\/187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/96"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}