0% found this document useful (0 votes)
139 views

Python

The document discusses various Python literals and data types. It describes numeric, string, character, boolean, and collection literals. It then covers fundamental Python data types like numbers, lists, tuples, strings, sets, and dictionaries. It provides examples of defining each data type and using basic operations on them, like slicing and type checking. It also discusses converting between different data types in Python.

Uploaded by

tarek hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views

Python

The document discusses various Python literals and data types. It describes numeric, string, character, boolean, and collection literals. It then covers fundamental Python data types like numbers, lists, tuples, strings, sets, and dictionaries. It provides examples of defining each data type and using basic operations on them, like slicing and type checking. It also discusses converting between different data types in Python.

Uploaded by

tarek hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Literals

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

String literals A string literal is a sequence of characters Single Double Triple


surrounded by quotes.

character literal a character literal is a single character Single Double


surrounded

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

character literal a character literal is a single character Single Double


surrounded

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.

Python List List is an ordered sequence of items.

All the items in a list do not need to be of the same type.


Items separated by commas are enclosed within brackets [ ].

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.

It is defined within parentheses () where items are separated


by commas.

We can use the slicing operator [] to extract items but we


cannot change its value.
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.

String is sequence of Unicode characters. We


Python Strings can use single quotes or double quotes to
represent strings. Multi-line strings can be
denoted using triple quotes, ''' or """.

Just like a list and tuple, the slicing operator [ ] can be


used with strings. Strings, however, are immutable.
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.

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.

We can perform set operations like union, intersection on


two sets. Sets have unique values. They eliminate
duplicates.

Since, set are unordered collection, indexing has no


meaning. Hence, the slicing operator [] does not work.
Data types
Since everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.

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.

You might also like