Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What Are Python Literals?
#1
What Are Python Literals?

I have been doing a lot of research and keep coming across vague and conflicting definitions of what literals are in Python.

The most common vague description is a literal is literally the value you are wanting to assign to a variable name. For example: in num = 5, the 5 is literally what it says it is. That just doesn't say anything at all to me. Couldn't I also say that a file is also literally what it says it is? If I make a computer class, isn't that literally what I say it is?

Another common description is that a literal is a shortcut constructor to common data types such as integers, strings, and Booleans. For example:
instead of writing: num = int(5)
I just write out: num = 5

Now I know that int() method is commonly used to change data types (such as int(5.0). But is it not also the constructor for the int class?

Thanks!
Julie
Reply


Messages In This Thread
What Are Python Literals? - by Julie - Sep-22-2020, 05:36 PM
RE: What Are Python Literals? - by bowlofred - Sep-22-2020, 06:28 PM
RE: What Are Python Literals? - by metulburr - Sep-22-2020, 06:31 PM
RE: What Are Python Literals? - by buran - Sep-22-2020, 06:35 PM
RE: What Are Python Literals? - by Julie - Sep-22-2020, 07:46 PM
RE: What Are Python Literals? - by ndc85430 - Sep-22-2020, 07:55 PM
RE: What Are Python Literals? - by Julie - Sep-22-2020, 08:57 PM
RE: What Are Python Literals? - by bowlofred - Sep-22-2020, 11:58 PM
RE: What Are Python Literals? - by Julie - Sep-23-2020, 02:10 PM
RE: What Are Python Literals? - by deanhystad - Sep-22-2020, 11:51 PM
RE: What Are Python Literals? - by perfringo - Sep-23-2020, 04:49 PM
RE: What Are Python Literals? - by Gribouillis - Sep-23-2020, 05:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  replace in code vs literals Skaperen 3 2,547 Mar-30-2021, 12:37 AM
Last Post: Skaperen
  string literals in a list. Not what I expected. tycarac 3 2,766 Dec-28-2019, 05:31 AM
Last Post: tycarac
  parenthesis around a tuple of literals in a for Skaperen 2 2,241 Aug-25-2019, 03:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020