Aryan PrajapatKnowledge Contributor
What are Literals in Python and explain about different Literals?
What are Literals in Python and explain about different Literals?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
A literal in python source code represents a fixed value for primitive data types. There are 5 types of literals in python-
1. String literals– A string literal is created by assigning some text enclosed in single or double quotes to a variable. To create multiline literals, assign the multiline text enclosed in triple quotes. Eg.name=”Tanya”.
2. A character literal– It is created by assigning a single character enclosed in double quotes. Eg. a=’t’.
3. Numeric literals include numeric values that can be either integer, floating point value, or a complex number. Eg. a=50.
4. Boolean literals– These can be 2 values- either True or False.
5. Literal Collections– These are of 4 types-
a) List collections-Eg. a=[1,2,3,’Amit’]
b) Tuple literals- Eg. a=(5,6,7,8)
c) Dictionary literals- Eg. dict={1: ’apple’, 2: ’mango, 3: ’banana`’}
d) Set literals- Eg. {“Tanya”, “Rohit”, “Mohan”}
6. Special literal- Python has 1 special literal None which is used to return a null variable.