alternative
  • Home (current)
  • About
  • Tutorial
    Technologies
    SQL -Structured Query Language
    Python
    Ethical Hacking
    Java
    .net Framework
    Placement Preparation
    Quantitative Aptitude
    View All Tutorial
  • Quiz
    SQL -Structured Query Language
    Quantitative Aptitude
    Java
    View All Quiz Course
  • Q & A
    Quantitative Aptitude
    Java
    View All Q & A course
  • Programs
  • Articles
    Artificial Intelligence & Machine Learning Project
    How to publish your local website on github pages with a custom domain name?
    How to download and install Xampp on Window Operating System ?
    How To Download And Install MySql Workbench
    How to install Pycharm ?
    How to install Python ?
    How to download and install Visual Studio IDE taking an example of C# (C Sharp)
    View All Post
  • Tools
    Program Compiler
    Sql Compiler
    Replace Multiple Text
    Meta Data From Multiple Url
  • Contact
  • User
    Login
    Register

Python - Things to know before proceed - Literals Tutorial

Literal is a value given to entities like variables or constants.

The following type of literals in python are:-

1] Numeric Literals

Numeric Literals are immutable ( unchangeable). Numeric literals belong to 3 different types of numeric types i.e Integer, float, and complex.

Example:-

b = 0b101010  #Binary Literals
d = 123       #Decimal Literal
h = 0x12a     #Hexadecimal Literal
o = 0o215     #Octal Literal

#Float Literal
float1 = 12.7
float2 = 3.5e2

#Complex Literal
z = 1 + 3.14j

print(b, d, h, o)
print(float1, float2)
print(z, z.imag, z.real)

 

2] String Literals

String literal is a sequence of string which can be formed by enclosing a string inside quotes in a different sequence. It can include single, double, or triple double-quotes.

Some of the examples of string literals are:-

i) Single Line String – For a Single-line string we can use a text between single quotes or double-quotes.

Example:-

Str1 = ‘Welcome to fresherbell’
Str2 =  “Welcome to fresherbell”

ii) Multi-Line String – For multi-line string, we can use a text between triple double quotes or adding a backslash at the end of each line.

Using Triple Quote

Example:-

str1 = """Welcome
to
Fresherbell"""

print(str1);

Using Back Slash after each Line

Example:-

str2 = "Welcome \
to \
Fresherbell"

print(str2);

 

3] Boolean Literals

Boolean literals can have two values: true or false. depending upon the condition.

In python, True represents a value 1, and False represents a value 0.

x = (1 == True)   #it will check whether 1 is equal to True or not
y = (1 == False)  #it will check whether 1 is equal to False or not
a = True + 1     #true = 1
b = False + 3   #false = 0

print("x =", x)
print("y =", y)
print("a =", a)
print("b =", b)

 

4] Special Literal

In Python, there is one special literal i.e None. None value can be used to specify that the field has not been created.

It can also be used to end the list.

For example-

a=1
b=None

print(a)    
print(b) 

 

5] Literal Collections

There are four types of literal collection in python. Those are List Literal, Tuple Literal, Dict Literal, and Set Literal.

For example:-

list_1=['Fresherbell',2, 2.33]   #List
tuple_1=(1,2,['Fresherbell',4,'Tutorial'])  #Tuple
dict_1={1:'Hello',2:'World',3:'in',4:'Python'}  #Dictionary
set_1={'Welcome','To','Fresherbell'}  #Set

print(list_1)
print(tuple_1)
print(dict_1)
print(set_1)  #Whenerver you will print set, everytime order will change

 

Python

Python

  • Introduction
  • Installation and running a first python program
    • How to install Python ?
    • Running 1st Hello World Python Program
    • How to install Pycharm ?
  • Things to know before proceed
    • Escape Characters/Special Characters
    • Syntax ( Indentation, Comments )
    • Variable
    • Datatype
    • Keyword
    • Literals
    • Operator
    • Precedence & Associativity Of Operator
    • Identifiers
    • Ascii, Binary, Octal, Hexadecimal
    • TypeCasting
    • Input, Output Function and Formatting
  • Decision control and looping statement
    • if-else
    • for loop
    • While loop
    • Break Statement
    • Continue Statement
    • Pass Statement
  • Datatype
    • Number
    • List
    • Tuple
    • Dictionary
    • String
    • Set
    • None & Boolean
  • String Method
    • capitalize()
    • upper()
    • lower()
    • swapcase()
    • casefold()
    • count()
    • center()
    • endswith()
    • split()
    • rsplit()
    • title()
    • strip()
    • lstrip()
    • rstrip()
    • find()
    • index()
    • format()
    • encode()
    • expandtabs()
    • format_map()
    • join()
    • ljust()
    • rjust()
    • maketrans()
    • partition()
    • rpartition()
    • translate()
    • splitlines()
    • zfill()
    • isalpha()
    • isalnum()
    • isdecimal()
    • isdigit()
    • isidentifier()
    • islower()
    • isupper()
    • isnumeric()
    • isprintable()
    • isspace()
    • istitle()
  • Python Function
    • Introduction
  • Lambda Function
    • Lambda Function
  • Python Advanced
    • Iterators
    • Module
    • File Handling
    • Exceptional Handling
    • RegEx - Regular Expression
    • Numpy
    • Pandas

About Fresherbell

Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique

Important Links

Don't hesitate to give us a call or send us a contact form message

Terms & Conditions
Privacy Policy
Contact Us

Social Media

© Untitled. All rights reserved. Demo Images: Unsplash. Design: HTML5 UP.