86% found this document useful (7 votes)
3K views

PPT

This document provides an introduction to Python and its main data types. It discusses that Python is an interpreted, object-oriented programming language created by Guido van Rossum in 1991. It emphasizes code readability and allows programmers to express concepts in fewer lines of code. The main data types covered are numbers, strings, lists, tuples, dictionaries, and sets. For each data type, examples are provided of how to define and access values of that type in Python.

Uploaded by

Abhishek jain
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
86% found this document useful (7 votes)
3K views

PPT

This document provides an introduction to Python and its main data types. It discusses that Python is an interpreted, object-oriented programming language created by Guido van Rossum in 1991. It emphasizes code readability and allows programmers to express concepts in fewer lines of code. The main data types covered are numbers, strings, lists, tuples, dictionaries, and sets. For each data type, examples are provided of how to define and access values of that type in Python.

Uploaded by

Abhishek jain
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/ 24

Submit By:-Abhishek Sankhala

Batch:-Python
 Introduction Of Python:-

 Datatypes in python :-
Number

String List

Tuple Dictionary Set


 Python is a general-purpose interpreted, interactive,
object-oriented, and high-level programming
language.

 It was created by Guido van Rossum during 1991.

 It was mainly developed for emphasis on code


readability, and its syntax allows programmers to
express concepts in fewer lines of code.

 By using python we can develop console based


application ,windows based application ,web based
application and other type application also.
 Windows Based Application:- tkinter, pyQt5, Wxpython etc .

 Web Based Application:- Django, Flask etc.

 Console Based Application:- Python core .

 Platform Independent:-Python programs can be developed and


executed on multiple operating system platforms.

 Internally, Python converts the source code into an intermediate form


called bytecodes which is then translated into native language of
specific computer to run it.

 It provides very high-level dynamic data types and supports dynamic


type checking.
 Number
 List
 String
 Tuple
 Dictionary
 Set
 Numbers:-Variables of numeric types are created when
we assign a value to them.

◦ 1.Integer:-Int, or integer, is a whole number,


positive or negative, without decimals, of unlimited
length.
Examples:-5, -8, 43, -234, 99933

2.Float:-Float, or "floating point number" is a number,


positive or negative, containing one or more
decimals.
Examples:-6.8, 24e12, -4e-2
2e3 = 2000, scientific notation
Complex numbers:-Complex numbers are
written with a "j" as the imaginary part.
Examples:-4+3j, 8.0+4.6j

Booleans:-Boolean values are the two constant


objects True or False.
(a) The built-in function bool() can be used to
cast any value to a Boolean,

 We can use the type() function to know which class a


variable or a value belongs to.
 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))
 5 is of type <class ‘int'>

 2.0 is of type <class 'float'>

 (1+2j) is complex number?


True
 Strings are immutable sequence of characters (text)

 These are inserted either in “ ” or ‘ ’.

 A double quote (“ ”) can contain single quote (‘ ’), e.g., “


‘dog’, ‘cat’ ” in a string

 and vice versa, e.g., ‘ ”dog”, “cat” ’ in a string

 They can also be in triple single or double quotes:


‘’’_____‘‘‘ or “”” “””.

 This is used for multi-line commenting


Example:-
 # all of the following are equivalent
my_string = 'Hello‘
print(my_string)

 my_string = "Hello“
print(my_string)

 my_string = '''Hello''‘
print(my_string)

# triple quotes string can extend multiple lines


my_string = """Hello, welcome to the world of
Python""“
print(my_string)
 Output:-

 Hello
 Hello
 Hello
 Hello, welcome to
the world of Python
 List is an ordered collection of objects

 List is the collection of heterogeneous element.

 List is modifiable (mutable).

 They can have elements of different types:-

 (Int,Float,Bool,Str,List,Tuple,Dictionary,Set)

 Elements are comma separated in a [ ].


 List stores duplicate element.

 List can be traversed as per index basis.

 List can be single dimensional and Multi


dimensional.

 Example:-
 x = ['apple', 3, [4.0, 5.0]] # multi-type list
 Lists start counting from 0 on the left side (using +
numbers) and - 1 from the right side

 x = ['River', 'Lake', 'Rock', 'Water', 'Air']

X=[ ‘River ‘Lake’ ‘Rock’ ‘Water’ ‘Air’ ]

+ index 0 1 2 3 4

- Index -5 -4 -3 -2 -1
 Output:-

 X[2] :- ‘Rock’

 X[-5] :- ‘River’

 X[:3] :- ['River', 'Lake', 'Rock']

 X[0:3] :- ['River', 'Lake', 'Rock'] # includes 0 but


excludes 3

 x[3:10] :-['Water', 'Air'] # ignores if the items don’t exist

 x[3:] :- ['Water', 'Air'] # index 3 and higher


 Are similar to lists but are immutable (like strings).

 can only be created but not changed.

 Tuple allows duplication.

 we use x=( ) to create tuples.

 Many of the functions and operators that work with


lists also work for tuples, e.g.:
len(), min(), max(), and the +, and * operands.

 Tuple is basically used for read only operations.


 x = () # create an empty tuple
 print x # prints ()

 (Mercury, Venus, Earth, Mars) = (1, 2, 3, 4)


Earth
 Output:- 3
 Dictionary is denoted by curly braces{}.

 Values in a dictionary are accessed via keys that are not just
numbers. They can be strings and other Python objects. Keys point
to values.

 Both lists and dictionaries store elements of different types.

 Hold unique key but value can be duplicate.


 Those in dictionaries are unordered.

 x = {} # create an empty dictionary

 dictionary with integer keys my_dict = {1: 'apple', 2: 'ball'}

 dictionary with mixed keys my_dict = {'name': 'John', 1: [2, 4, 3]}

 using dict() my_dict = dict({1:'apple', 2:'ball'})

 from sequence having each item as a pair


my_dict = dict([(1,'apple'), (2,'ball')])
 x = {} # declare x as a dictionary
x["Venus"] = 2 # indexing with non numbers
(in this case string)

 y = {}
 y['Earth'] = 3
x['Venus'] * y ['Earth']
# this cannot be done with lists (need int indices)
 Output:- 6
 A set is an unordered collection of items.

 Every element is unique (no duplicates).

 immutable (which cannot be changed).

 We can add or remove items from it.

 Sets can be used to perform mathematical set operations


like union, intersection, symmetric difference etc.
 # set of integers
 my_set = {1, 2, 3}
print(my_set)
Output:- {1, 2, 3}

 # set of mixed datatypes


my_set = {1.0, "Hello", (1, 2, 3)}
print(my_set)
Output:- {1.0, 'Hello', (1, 2, 3)}

 # set do not have duplicates


my_set = {1,2,3,4,3,2}
print(my_set)
Output: {1, 2, 3, 4}
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy