{"id":5637,"date":"2021-05-10T10:41:27","date_gmt":"2021-05-10T05:11:27","guid":{"rendered":"https:\/\/python-programs.com\/?p=5637"},"modified":"2021-11-22T18:42:48","modified_gmt":"2021-11-22T13:12:48","slug":"literals-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/literals-in-python\/","title":{"rendered":"Literals in Python"},"content":{"rendered":"
Literals are a type of notation used in source code to represent a fixed value. They can also be defined as raw values or data that are given in variables or constants.<\/p>\n
This article will teach you about the various types of literals in Python.<\/p>\n
In Python, there are various types of literals. As an example,<\/p>\n
In Python, numerical literals represent numbers and can be of the following types:<\/p>\n
In Python, only True and False are Boolean literals.<\/p>\n
A string literal is made by enclosing a text(a set of characters) in single(\u201d), double(\u201c\u201d), or triple(\u201c\u201d) quotes. We can write multi-line strings or show in the desired way by using triple quotes.<\/p>\n
# string literals in python\r\n# single quote representation of string\r\nstring1 = 'BTechGeeks'\r\n\r\n# double quotes representation of string\r\nstring2 = \"BTechGeeks\"\r\n\r\n# multiline representation of string\r\nstring3 = '''BTech\r\n Geeks\r\n Platform'''\r\n\r\nprint('single quote string:', string1)\r\nprint('double quote string:', string2)\r\nprint('multiline string :', string3)\r\n<\/pre>\nOutput:<\/strong><\/p>\n
single quote string: BTechGeeks\r\ndouble quote string: BTechGeeks\r\nmultiline string : BTech\r\n\t\tGeeks\r\n\t\t\tPlatform<\/pre>\n4)Special literals<\/h3>\n
There is one special literal in Python (None). A null variable is described by the word \u2018none.’ When \u2018None’ is contrasted to something other than another \u2018None,’ it returns false.<\/p>\n
# special literal none\r\nspecial = None\r\nprint(special)\r\n<\/pre>\nOutput:<\/strong><\/p>\n
None<\/pre>\n5)Escape characters<\/h3>\n
\n
- \\<\/strong>\u00a0:\u00a0 Newline continuation<\/li>\n
- \\\\<\/strong>\u00a0: Display a single \\<\/li>\n
- \\\u2019<\/strong>\u00a0: Display a single quote<\/li>\n
- \\\u201d<\/strong>\u00a0: Display a double quote<\/li>\n
- \\b<\/strong>\u00a0: Backspace<\/li>\n
- \\n<\/strong>\u00a0: New Line<\/li>\n
- \\t<\/strong>\u00a0: Horizontal Tab<\/li>\n
- \\v<\/strong>\u00a0: Vertical Tab<\/li>\n
- \\r<\/strong>\u00a0: Enter<\/li>\n<\/ul>\n
Related Programs<\/strong>:<\/p>\n
\n
- convert integer to string in python<\/li>\n
- how to web scrape with python in 4 minutes<\/li>\n
- dictionaries in python<\/li>\n
- how to create and initialize a list of lists in python<\/li>\n
- web crawling and scraping in python<\/li>\n
- how to append text or lines to a file in python<\/li>\n
- python check if a value exists in the dictionary<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
Literals are a type of notation used in source code to represent a fixed value. They can also be defined as raw values or data that are given in variables or constants. This article will teach you about the various types of literals in Python. Python Literals In Python, there are various types of literals. …<\/p>\n