Showing posts with the label Python - Literals

Python Programming Language - Literals

Python literals can be defined as data given in a variable or constant.  Python supports several types of literals. String literals String literals can be formed by enclosing text in quotation marks. We can use either single or double quotes to create a string. Example: "Carl" , '9876' Python supports two types of strings: 1.   Single lines. Strings that end in one line are called one-liners. Example: message= 'Hello world!' 2. Multi-line string. A piece of text consisting of several lines is known as a multiline string. There are two ways to create multiline strings: 1.  Adding a black slash at the end of each line. message= 'Hello \ Rick'   print(message) Console output: Hello Rick 2. Use triple quotes. Example: message= '''welcome to python world'''   print (message) Console output: welcome  to python world Numeric literals Numeric literals are immutable. Numeric literals can belong to the following four different numeric