what are Literals in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what are Literals in python?

Hi everyone, I need someone to explain the term literal in python, I searched it on the google but I still have difficulty on the term.

12th Aug 2019, 2:33 PM
Surafel Kassahun
Surafel Kassahun - avatar
1 Answer
+ 3
When you want to store a value in a variable, depending on what you want, you have to write it differently. x = 5 will be an int, x = 5.0 will be a float, x = '5' will be str, x = [5] will be a list with an int in it. These different shapes, that tell Python, what exactly you want, are called literals. {5, 7} is a set literal, {'a': 7, 'b': 12} is a dict literal, (7, 5, 3) is a tuple literal. A little bit clearer now?
12th Aug 2019, 3:06 PM
HonFu
HonFu - avatar