Python Literals
Python Literals
Python Java JavaScript SQL C++ HTML CSS React
← prev next →
Python Literals
Python Literals can be defined as data that is given in a variable or constant.
1. String literals:
String literals can be formed by enclosing a text in the quotes. We can use both single
as well as double quotes to create a string.
Example:
"Aman" , '12345'
Types of Strings:
a) Single-line String- Strings that are terminated within a single-line are known as
Single line Strings.
Example:
text1='hello'
text1='hello\
user'
print(text1)
'hellouser'
Example:
str2='''''welcome
to
SSSIT'''
print str2
Output:
welcome
to
SSSIT
#Float Literal
float_1 = 100.5
float_2 = 1.5e2
#Complex Literal
a = 5+3.14j
print(x, y, z, u)
print(float_1, float_2)
print(a, a.imag, a.real)
Output:
x = (1 == True)
y = (2 == False)
z = (3 == True)
a = True + 10
b = False + 10
print("x is", x)
print("y is", y)
print("z is", z)
print("a:", a)
print("b:", b)
Output:
x is True
y is False
z is False
a: 11
b: 10
None is used to specify to that field that is not created. It is also used for the end of
lists in Python.
val1=10
val2=None
print(val1)
print(val2)
Output:
10
None
V. Literal Collections.
Python provides the four types of literal collection such as List literals, Tuple literals,
Dict literals, and Set literals.
List:
List contains items of different data types. Lists are mutable i.e., modifiable.
The values stored in List are separated by comma(,) and enclosed within square
brackets([]). We can store different types of data in a List.
list=['John',678,20.4,'Peter']
list1=[456,'Andrew']
print(list)
print(list + list1)
Output:
Dictionary:
Example
Output:
Tuple:
Example
tup = (10,20,"Dev",[2,3,4])
print(tup)
Output:
Set:
set = {'apple','grapes','guava','papaya'}
print(set)
Output:
{'guava', 'apple', 'papaya', 'grapes'}
← prev next →
Related Posts
4 min read
Python Tutorial
| Python Programming Language Python is one of the most popular and widely
used programming language in nowadays, because of its simplicity, extensive
features and support of libraries. Python also have clean and simple syntax
which makes it beginner-friendly, while it also provides powerful libraries and
frameworks...
4 min read
Python Comments
We'll study how to write comments in our program in this article. We'll also learn
about single-line comments, multi-line comments, documentation strings, and
other Python comments. Introduction to We may wish to describe the code we
develop. We might wish to take notes of why a...
3 min read
Python Features
Features of Python From the development of Ada Lovelace's machine algorithm
in 1843 to the latest and popular high-level programming languages like C++,
Python, and Java, a wide range of programming languages have been
developed by programmers in order to solve real-world challenging problems.
However, not...
13 min read
History of Python
Programming Language Python ranks among the most used and flexible
coding languages of the present day. It is also incredibly easy to read, write,
implement, and is well-supported with a variety of libraries. Based on these
factors, Python is renowned for numerous functions like building...
5 min read
4 min read
Python Operators
In the following tutorial, we will discuss about the operators used in the Python
programming language. An Introduction to Operators in Python In general,
Operators are the symbols used to perform a specific operation on different
values and variables. These values and variables are considered as the...
13 min read
Python Keywords
Every scripting language has designated words or keywords, with particular
definitions and usage guidelines. Python is no exception. The fundamental
constituent elements of any Python program are Python keywords. This tutorial
will give you a basic overview of all Python keywords and a detailed discussion
of...
13 min read
Python Applications
Applications of Python Programming Python is known for its general-purpose
nature that makes it applicable in almost every domain of software
development. Python makes its presence in every emerging field. It is the
fastest-growing programming language and can develop any application. Top 10
Here, we are specifying...
3 min read
Python Java
Javascript HTML
Database PHP
C++ React
B.Tech / MCA
Data
DBMS
Structures
Operating
DAA
System
Computer Compiler
Network Design
Computer Discrete
Organization Mathematics
Ethical Computer
Hacking Graphics
Web Software
Technology Engineering
Cyber
Automata
Security
C C++
Programming
Java .Net
Python Programs
Control Data
System Warehouse
Preparation
Aptitude Reasoning
Verbal Interview
Ability Questions
Company
Questions