Literals in Python.

Literls:-

Literal is a raw data given in a variable or consatant. In python, there are various type of literls.

Type of Literls:-

1. String 2. Numeric 3. Boolean 4. Special

String:

String is an immutable data type. String formed by enclosing a text in the qutoes. Both single and double quotes can be used.

Example:

string='This is python' char="C" print(string) print(char)

Output:

This is python C

Numeric Literls:

Numeric literals are immutable data type. Numeric literals can belong to four different Numeric type.

Types of Numeric Literls:

.Integer .Long .Float .Complex

integer(signed integer):

Number( can be +ve and -ve) with nuber fractional part.

Example:

230

Long(long integer):

Integer of unlimited size followed by lower case or uppercase.

Example

8703285L

Float(folating point):

Real numer with both integer and fractional part.

Example

35.2

Complex(complex):

In the form of 'a+bj' where 'a' forms the real part and 'b' form the imaginary part of complex.

Example

323.14j

Boolean Literls:

A boolean literl can have two value:True or False.

Example

x=(2==2) y=(4==5) a=True+10 b=False+10 print("x is",x) print("Y is",y) print("a:",a) print("b:",b)

Output:

x is True Y is False a: 11 b: 10

Special Literls:

Python has one special literls "None".

Example

val1=10 val2=None print(val1) print(val2)

Output:

10 None

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.