Python
Python
Literal is a raw data given in a variable or constant. In Python, there are various types of literals
they are as follows:
Numeric Literals Numeric Literals are immutable (unchangeable). Integer Float Complex
Boolean literals A Boolean literal can have any of the two True False
values
Literals
Literal is a raw data given in a variable or constant. In Python, there are various types of literals
they are as follows:
None We use it to specify that the field has not been created.
Literal Dictionar
There are four different literal collections List Tuple Set
Collections y
Boolean literals A Boolean literal can have any of the two True False
values
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.
Python Numbers They are defined as int, float and complex classes in Python.
use the type() function to know which class a variable or a value belongs to.
The isinstance() function is used to check if an object belongs to a particular
class.
a=5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.
Lists are mutable, meaning, the value of elements of a list can be altered.
a = [ 5,2,3,’python’]
print(a, "is of type", type(a))
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.
Python List We can use the slicing operator [ ] to extract an item or a range of items from a
list. The index starts from 0 in Python.
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.
Tuple is an ordered sequence of items same as
Python Tuple a list. The only difference is that tuples are
immutable. Tuples once created cannot be
modified.
Tuples are used to write-protect data and are usually faster than lists
as they cannot change dynamically.
Python Set
Set is an unordered collection of unique items. Set is
defined by values separated by comma inside braces { }.
Items in a set are not ordered.
Python
Dictionary
Dictionary is an unordered collection of
key-value pairs. It is generally used when
we have a huge amount of data.
Dictionaries are optimized for retrieving
data. We must know the key to retrieve the
value.
In Python, dictionaries are defined within
braces {} with each item being a pair in the
form key:value. Key and value can be of
any type.
Conversion between data types
We can convert between different data types by using different
type conversion functions like int(), float(), str(), etc.