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

Keywords in python

The document provides an overview of data types and keywords in Python, detailing various data types such as numbers, sequences (strings, lists, tuples), dictionaries, sets, and booleans. It also explains Python keywords, their categories, and their specific functions within the language. The content is aimed at helping readers understand the foundational elements of Python programming.
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)
11 views

Keywords in python

The document provides an overview of data types and keywords in Python, detailing various data types such as numbers, sequences (strings, lists, tuples), dictionaries, sets, and booleans. It also explains Python keywords, their categories, and their specific functions within the language. The content is aimed at helping readers understand the foundational elements of Python programming.
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/ 18

K.C.S.

KASI NADAR COLLEGE OF ARTS &


SCIENCE
(Belongs to S.V.H.N.A.Dharma Fund)

DATATYPES & KEYWORDS IN


PYTHON
By,
Mrs.B.VIJAYALAKSHMI,
Assistant Professor,
Department Of Computer Science.
VALUES AND DATATYPES

• Value :

 A Value can be any letter, number or string.

Eg, Values are 2, 42.0, and 'Hello, World!'. (These values


belong to different datatypes.)

• Data type:
 Every value in Python has a data type.

 It is a set of values, and the allowable operations on those


values.

• type() function is used to determine the type of datatype.


DATATYPES IN PYTHON
NUMBERS
• Number data type stores Numerical Values.
• This data type is immutable [i.e. values/items cannot be changed].
• Python supports integers, floating point numbers and complex numbers.
Integers Long Float Complex
They are often called as They are long integers. They are written with a They are of the form a+bj
integers or int. decimal point dividing the Where a and b are floats
integer and the fractional and j represents the square
They are positive or They can also be parts. root of -1(which is an
negative whole numbers represented in octal and imaginary number).
with no decimal points. hexa decimal
representation Real part of the number is
a, and the imaginary part is
b.

Eg : 65 Eg: 5692431L Eg : 56.778 Eg : 5+3i


SEQUENCE

• A sequence is an ordered collection of items, indexed by positive integers.


• It is a combination of mutable (value can be changed) and immutable
(values cannot be changed) datatypes.

• There are three types of sequence data type available in Python, they are
1. Strings

2. Lists

3. Tuples
STRINGS
• A String in Python consists of a series or sequence of characters.
Single quotes(' ') E.g., 'This a string in single quotes' ,
Double quotes(" ") E.g., "'This a string in double quotes'" ,
Triple quotes(""" """)E.g., """This is a paragraph. It is made up of multiple lines
and sentences."""
• Individual character in a string is accessed using a subscript(index).
• Strings are Immutable i.e the contents of the string cannot be changed after it
is created.
LISTS

• List is an ordered sequence of items. Values in the list are called


elements /items.
• It can be written as a list of comma-separated items (values) between
square brackets[].
• Items in the lists can be of different datatypes.
Eg : lt = [ 10, -20, 15.5, ‘ABC’, “XYZ” ]
TUPLES
• A tuple is same as list, the set of elements is enclosed in parentheses (
).
• A tuple is an immutable list.i.e. once a tuple has been created, you
can't add elements to a tuple or remove elements from the tuple.
Benefit of Tuple:
• Tuples are faster than lists.
• If the user wants to protect the data from accidental changes, tuple
can be used.
• Tuples can be used as keys in dictionaries, while lists can't.
Altering the tuple data type leads to error.
Eg : tpl = ( 10, -20, 15.5, ‘ABC’, “XYZ” )
DICTIONARIES
• A dictionary maps keys to values.
• Lists are ordered sets of objects, whereas dictionaries are unordered sets.
• Dictionary is created by using curly brackets. i,e.{ }
• Dictionaries are accessed via keys and not via their position.
• The values of a dictionary can be any Python data type. So dictionaries
are unordered key-valuepairs(The association of a key and a value is
called a key- value pair)
Eg : Creating a dictionary:
>>> food = {"ham":"yes", "egg" : "yes", "rate":450 }
SET :
• Python also provides two set types, set and frozenset.
• The set type is mutable, while frozenset is immutable.
• They are unordered collections of immutable objects.

BOOLEAN :
• The boolean data type is either True or False.
• In Python, boolean variables are defined by the True and False
keywords.
• Note the keywords True and False must have an Upper Case first letter.
KEYWORDS

• Python keywords are special reserved words that have


specific meanings.
• Python 3.8, there are thirty-five keywords.
• The keyword module in python provides two helpful members for dealing with
keywords.
kwlist provides a list of all the python keywords for the version which you
are running.
iskeyword() provides a way to determine if a string is also a keyword.
Eg :
>>> import keyword
>>> keyword.kwlist
O/P : ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']
>>> len(keyword.kwlist)
• Value Keywords : True, False, None

• Always Written in upper case.


• True and False keywords can be assigned to variables
and compared to directly.

• None keyword represents no value.


• None keyword is the default value returned by a
function if it doesn’t have a return statement.
• Operators keywords : and, or, not, in, is

• in keyword is called a membership operator.


• Return True or False indicating whether the element was
found in the container.
• in keyword works with all type of containers such as lists,
dictionaries and sets.

• is keyword is an identity check.


• Determines whether two objects are exactly the same
• Control flow keywords : if, elif, else
• Allows to use conditional logic and execute code given
certain conditions.

• Iteration keywords : for, while, break, continue, else


• Used to create and work with loops.

• Returning keywords : return, yield


• Used to specify what gets returned from functions or
methods.
• Structure keywords : def, class, with, as, pass, lambda
• def is used to define a function or method of a class.
• class is used to define the class in python.
• with is used for working with file I/O in python.

• Variable handling keywords : del, global, nonlocal


• Used to work with variables.
• import keywords : import, from, as
• Used for importing the modules into your program.

• Exception Handling keywords : try, except, raise, finally,


else, assert
• Used for raising and catching of exceptions.

• Asynchronous Programming keywords : async, await


THANK YOU!!!

You might also like