Easy learning with example program codes

Python Literals

Python Literals:

Literals are the constant values or the variable values used in a Python code. There are mainly five types of literals used in PYTHON:

  • String Literals
  • Numeric Literals
  • Boolean Literals
  • Special Literals
  • Collection Literals

String literals:

In Python, String literals are characterised either by single quotation marks, or double quotation marks surrounding them. The string literals can be Single line or Multiple line strings.

Numeric literals:

Numeric Literals in Python can be of three numeric types:

  1. int
  2. float
  3. complex

1. Int

Int can be defined as a collection of both positive and negative integers (without decimals).

2. Float

Float can be defined as a collection of both positive and negative floating point numbers (with decimals) along with the scientific numbers with an “e” to indicate the power of 10.

3. Complex

Complex numbers are the numbers having both a real and imaginary part in the form of x +yj, where x is real and y is imaginary.

Boolean literals:

Boolean literals can be either 0 or 1 i.e, either True or False.

 Special literals.

None is a special literal defined in Python to specify the end of a list or to represent a NULL value.

Literal Collections.

Beside Lists, Python supports Tuples and Dictionary to store a collection of literals in a single variable.

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki