SlideShare a Scribd company logo
in
CLOUD
• What is Python?
• Features of Python
• Who uses Python?
• Applications
• How to download python
• Working with interactive prompt
• Dynamic
• Identifiers
• Keywords
• Python Syntax
CONTENTS (Day1)
• Python is a general purpose, dynamic, high-level, and
interpreted programming language.
• Created by Guido Van Rossum in 1989.
What is Python
1) Easy to Learn and Use
2) Expressive Language
3) Interpreted Language
4) Cross-platform Language
5) Free and Open Source-https://www.python.org/
6) Object-Oriented Language
7) Extensible
8) Large Standard Library
9) GUI Programming Support
10) Integrated
Python Features
Top Companies
Applications
How to download Python
Introduction to python
Introduction to python
Interactive interpreter prompt
Interactive interpreter prompt
Interactive interpreter prompt
Introduction to python
• When assigning to a variable, we do not need to
declare the data type of the values it will hold. This is
decided by the interpreter at runtime.
• We do not declare a variable, we directly assign to it.
Python is Dynamically-Typed
• A variable name is called an identifier and has to
follow some rules:
• Variables can have letters (A-Z and a-z), digits(0-9)
and underscores.
• It cannot begin with an underscore (_) or a digit.
• It cannot have whitespace and signs like + and -,
!, @, $, #, %.
• It cannot be a reserved keyword for Python.
• Variable names are case sensitive.
Identifiers
• These are 33 reserved words.
• You cannot use a word from this list as a name for
your variable or function.
• Python variable names are case-sensitive. The
variable ‘name’ is different than the variable ‘Name’
Reserved Keywords
• The term syntax is referred to a set of rules and
principles that describes the structure of a language.
Python Syntax
A Python program comprises logical lines. A NEWLINE token
follows each of those. The interpreter ignores blank lines.
The following line causes an error.
>>> print("Hi
How are you?")
Output:
SyntaxError: EOL while scanning string literal
Python Line Structure
• This one is an important Python syntax.
• We saw that Python does not mandate semicolons.
• A new line means a new statement. But sometimes, you may
want to split a statement over two or more lines.
Python Multiline Statements
• A docstring is a documentation string.
• As a comment, this Python Syntax is used to explain code.
• But unlike comments, they are more specific. Also, they are
retained at runtime. This way, the programmer can inspect
them at runtime.
"""
This function prints out a greeting
"""
print("Hi")
Python Docstrings
• Python doesn’t use curly braces to delimit blocks of code, this
Python Syntax is mandatory.
• You can indent code under a function, loop, or class.
• >>> if 2>1:
print("2 is the bigger person");
print("But 1 is worthy too");
Python Indentation
You can also fit in more than one statement on one line.
Do this by separating them with a semicolon.
>>> a=7;print(a);
Python Multiple Statements in One
Line
Python supports the single quote and the double quote for string
literals.
But if you begin a string with a single quote, you must end it with
a single quote. The same goes for double-quotes.
• >>> print('We need a break');
• >>> print("We need a ‘break'");
Python Quotations
• You can use the % operator to format a string to contain text
as well as values of identifiers.
• Use %s where you want a value to appear. After the string,
put a % operator and mention the identifiers in parameters.
Python String Formatters
I just printed 10 pages to the printer HP
Python String Formatters
• You can use the % operator to format a string to contain text
as well as values of identifiers.
• Use %s where you want a value to appear. After the string,
put a % operator and mention the identifiers in parameters.
Python String Formatters
I just printed 10 pages to the printer HP
Python Syntax ‘Comments’ let you store tags at the
right places in the code. You can use them to explain
complex sections of code. The interpreter ignores
comments. Declare a comment using an Hash(#).
>>>#this is a comment line
Python Comments
• Python allows us to assign a value to multiple
variables in a single statement which is also known as
multiple assignment.
• We can apply multiple assignments in two ways
either by assigning a single value to multiple
variables
or
• assigning multiple values to multiple variables.
Multiple Assignment
Multiple Assignment
Multiple Assignment
Anaconda
Anaconda Navigator
SPYDER
SPYDER
Python Data Types
• Variables can hold values of different data types.
• Python is a dynamically typed language hence we
need not define the type of the variable while
declaring it.
• The interpreter implicitly binds the value with its
type.
Python Data Types
• python enables us to check the type of the variable used in the program.
• Python provides us the type() function which returns the type of the
variable passed.
Python Data Types
Python data types are categorized into two as follows:
Mutable Data Types: Data types in python where the value
assigned to a variable can be changed
Immutable Data Types: Data types in python where the
value assigned to a variable cannot be changed
Python Data Types
Python-Numbers
• Number data types store numeric values.
• They are immutable data types, means that changing
the value of a number data type is not possible.
• For example −
• var1 = 1 var2 = 10
• You can also delete the reference to a number object
by using the del statement.
• Del var1
Python-Numbers
• Python supports four different numerical types −
• int (signed integers) − They are often called just integers or ints,
are positive or negative whole numbers with no decimal point.
• Long (long integers ) − Also called longs, they are integers of
unlimited size, written like integers and followed by an uppercase
or lowercase L.
• float (floating point real values) − Also called floats, they
represent real numbers and are written with a decimal point
dividing the integer and fractional parts.
• complex (complex numbers) − are of the form a + bJ, where a and
b are floats and J (or j) represents the square root of -1 (which is an
imaginary number).
Number Type Conversion
• But sometimes, you need to convert a number explicitly from
one type to another to satisfy the requirements of an
operator or function parameter.
• Type int(x) to convert x to a plain integer.
• Type long(x) to convert x to a long integer.
• Type float(x) to convert x to a floating-point number.
• Type complex(x) to convert x to a complex number with real
part x and imaginary part zero.
• Type complex(x, y) to convert x and y to a complex number
with real part x and imaginary part y. x and y are numeric
expressions
Number Type Conversion
Strings
• Strings are amongst the most popular types in
Python.
• We can create them simply by enclosing characters in
quotes. Python treats single quotes the same as
double quotes.
• var1 = 'Hello World!‘
• var2 = "Python Programming"
Accessing Values in Strings
• Python does not support a character type; these are treated
as strings of length one, thus also considered a substring.
• To access substrings, use the square brackets for slicing along
with the index or indices to obtain your substring.
Updating Strings
• You can "update" an existing string by (re)assigning a variable
to another string. The new value can be related to its previous
value or to a completely different string altogether.
String Special Operators
Strings
Python Lists
• Lists are the most versatile of Python's compound
data types.
• A list contains items separated by commas and
enclosed within square brackets ([]).
• To some extent, lists are similar to arrays in C.
• One difference between them is that all the items
belonging to a list can be of different data type.
Python Lists
Python Tuples
• A tuple is another sequence data type that is similar to
the list.
• A tuple consists of a number of values separated by
commas.
• Unlike lists, however, tuples are enclosed within
parentheses.
• The main differences between lists and tuples are: Lists
are enclosed in brackets ( [ ] ) and their elements and size
can be changed,
• while tuples are enclosed in parentheses ( ( ) ) and
cannot be updated.
• Tuples can be thought of as read-only lists.
Python Tuples
Python Dictionary
• A Python dictionary is a mapping of unique keys to
values. Dictionaries are mutable, which means they
can be changed.
• Dictionaries are enclosed by curly braces ({ }) and
values can be assigned and accessed using square
braces ([]).
Python Dictionary
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
Print( "dict['Name']: ", dict['Name'])
print ("dict['Age']: ", dict['Age'])
Dictionary Functions
• Len-The method len() gives the total length of the
dictionary.
• dict = {'Name': 'Zara', 'Age': 7};
• print (len(dict))
• Copy-The method copy() returns a shallow copy of the
dictionary.
• dict1 = {'Name': 'Zara', 'Age': 7};
• dict2 = dict1.copy()
• print "New Dictionary : %s" % str(dict2)
Introduction to python
• Keys-The method keys() returns a list of all the
available keys in the dictionary.
• my_dict = {'name':'Jack', 'age': 26}
• print "Value : %s" % dict.keys()
• Values-The method values() returns a list of all
the values available in a given dictionary.
• print "Value : %s" % dict.values()
Introduction to python
Set in Python
• A set is an unordered collection of items.
• Every element is unique (no duplicates) and
must be immutable (which cannot be
changed).
• my_set = {1, 2, 3}
• print(my_set)
Change a set in Python
• Sets are mutable. But since they are unordered,
indexing have no meaning.
• We can add single element using
the add() method and multiple elements using
the update() method.
• The update() method can take tuples,
lists, strings or other sets as its argument. In all
cases, duplicates are avoided.
Introduction to python
Remove elements from a set
• A particular item can be removed from set using
methods, discard() and remove().
• The only difference between the two is that,
while using discard() if the item does not exist in
the set, it remains unchanged.
• But remove() will raise an error in such condition.
• my_set.discard(4)
• print(my_set)
• my_set.remove(4)
Thank you

More Related Content

What's hot (20)

PPTX
Python
Aashish Jain
 
PPT
Python ppt
Mohita Pandey
 
PDF
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
PDF
Python Basics | Python Tutorial | Edureka
Edureka!
 
PDF
Python made easy
Abhishek kumar
 
PPTX
Python Functions
Mohammed Sikander
 
PDF
Introduction To Python
Vanessa Rene
 
PPTX
Python programming
Ashwin Kumar Ramasamy
 
PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PDF
Introduction to python
Agung Wahyudi
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Python basics
Hoang Nguyen
 
PPTX
Python strings presentation
VedaGayathri1
 
PDF
Set methods in python
deepalishinkar1
 
PPTX
Beginning Python Programming
St. Petersburg College
 
PDF
Begin with Python
Narong Intiruk
 
PPT
Introduction to Python
Nowell Strite
 
PPTX
Functions in Python
Kamal Acharya
 
PDF
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Python
Aashish Jain
 
Python ppt
Mohita Pandey
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
Python Basics | Python Tutorial | Edureka
Edureka!
 
Python made easy
Abhishek kumar
 
Python Functions
Mohammed Sikander
 
Introduction To Python
Vanessa Rene
 
Python programming
Ashwin Kumar Ramasamy
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Introduction to python
Agung Wahyudi
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python basics
Hoang Nguyen
 
Python strings presentation
VedaGayathri1
 
Set methods in python
deepalishinkar1
 
Beginning Python Programming
St. Petersburg College
 
Begin with Python
Narong Intiruk
 
Introduction to Python
Nowell Strite
 
Functions in Python
Kamal Acharya
 
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 

Similar to Introduction to python (20)

PPTX
Python-Basics.pptx
TamalSengupta8
 
PDF
CS-XII Python Fundamentals.pdf
Ida Lumintu
 
PPTX
1. python programming
sreeLekha51
 
PPTX
introduction to python programming concepts
GautamDharamrajChouh
 
PPTX
Chapter1 python introduction syntax general
ssuser77162c
 
PPTX
python_class.pptx
chandankumar943868
 
PPTX
Introduction to python for the abs .pptx
Mark Musah Ibrahim
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
ODP
Python slide.1
Aswin Krishnamoorthy
 
PDF
Python Programming
Saravanan T.M
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PDF
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
PPT
Python - Module 1.ppt
jaba kumar
 
PPTX
python
ultragamer6
 
PPTX
Python knowledge ,......................
sabith777a
 
PPTX
Python 01.pptx
AliMohammadAmiri
 
PPTX
Python variables and data types.pptx
AkshayAggarwal79
 
PDF
Python quick guide
Hasan Bisri
 
PPTX
2. Getting Started with Python second lesson .pptx
Primary2Primary2
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Python-Basics.pptx
TamalSengupta8
 
CS-XII Python Fundamentals.pdf
Ida Lumintu
 
1. python programming
sreeLekha51
 
introduction to python programming concepts
GautamDharamrajChouh
 
Chapter1 python introduction syntax general
ssuser77162c
 
python_class.pptx
chandankumar943868
 
Introduction to python for the abs .pptx
Mark Musah Ibrahim
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Python slide.1
Aswin Krishnamoorthy
 
Python Programming
Saravanan T.M
 
Fundamentals of Python Programming
Kamal Acharya
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Python - Module 1.ppt
jaba kumar
 
python
ultragamer6
 
Python knowledge ,......................
sabith777a
 
Python 01.pptx
AliMohammadAmiri
 
Python variables and data types.pptx
AkshayAggarwal79
 
Python quick guide
Hasan Bisri
 
2. Getting Started with Python second lesson .pptx
Primary2Primary2
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Ad

Introduction to python

  • 2. • What is Python? • Features of Python • Who uses Python? • Applications • How to download python • Working with interactive prompt • Dynamic • Identifiers • Keywords • Python Syntax CONTENTS (Day1)
  • 3. • Python is a general purpose, dynamic, high-level, and interpreted programming language. • Created by Guido Van Rossum in 1989. What is Python
  • 4. 1) Easy to Learn and Use 2) Expressive Language 3) Interpreted Language 4) Cross-platform Language 5) Free and Open Source-https://www.python.org/ 6) Object-Oriented Language 7) Extensible 8) Large Standard Library 9) GUI Programming Support 10) Integrated Python Features
  • 14. • When assigning to a variable, we do not need to declare the data type of the values it will hold. This is decided by the interpreter at runtime. • We do not declare a variable, we directly assign to it. Python is Dynamically-Typed
  • 15. • A variable name is called an identifier and has to follow some rules: • Variables can have letters (A-Z and a-z), digits(0-9) and underscores. • It cannot begin with an underscore (_) or a digit. • It cannot have whitespace and signs like + and -, !, @, $, #, %. • It cannot be a reserved keyword for Python. • Variable names are case sensitive. Identifiers
  • 16. • These are 33 reserved words. • You cannot use a word from this list as a name for your variable or function. • Python variable names are case-sensitive. The variable ‘name’ is different than the variable ‘Name’ Reserved Keywords
  • 17. • The term syntax is referred to a set of rules and principles that describes the structure of a language. Python Syntax
  • 18. A Python program comprises logical lines. A NEWLINE token follows each of those. The interpreter ignores blank lines. The following line causes an error. >>> print("Hi How are you?") Output: SyntaxError: EOL while scanning string literal Python Line Structure
  • 19. • This one is an important Python syntax. • We saw that Python does not mandate semicolons. • A new line means a new statement. But sometimes, you may want to split a statement over two or more lines. Python Multiline Statements
  • 20. • A docstring is a documentation string. • As a comment, this Python Syntax is used to explain code. • But unlike comments, they are more specific. Also, they are retained at runtime. This way, the programmer can inspect them at runtime. """ This function prints out a greeting """ print("Hi") Python Docstrings
  • 21. • Python doesn’t use curly braces to delimit blocks of code, this Python Syntax is mandatory. • You can indent code under a function, loop, or class. • >>> if 2>1: print("2 is the bigger person"); print("But 1 is worthy too"); Python Indentation
  • 22. You can also fit in more than one statement on one line. Do this by separating them with a semicolon. >>> a=7;print(a); Python Multiple Statements in One Line
  • 23. Python supports the single quote and the double quote for string literals. But if you begin a string with a single quote, you must end it with a single quote. The same goes for double-quotes. • >>> print('We need a break'); • >>> print("We need a ‘break'"); Python Quotations
  • 24. • You can use the % operator to format a string to contain text as well as values of identifiers. • Use %s where you want a value to appear. After the string, put a % operator and mention the identifiers in parameters. Python String Formatters I just printed 10 pages to the printer HP
  • 26. • You can use the % operator to format a string to contain text as well as values of identifiers. • Use %s where you want a value to appear. After the string, put a % operator and mention the identifiers in parameters. Python String Formatters I just printed 10 pages to the printer HP
  • 27. Python Syntax ‘Comments’ let you store tags at the right places in the code. You can use them to explain complex sections of code. The interpreter ignores comments. Declare a comment using an Hash(#). >>>#this is a comment line Python Comments
  • 28. • Python allows us to assign a value to multiple variables in a single statement which is also known as multiple assignment. • We can apply multiple assignments in two ways either by assigning a single value to multiple variables or • assigning multiple values to multiple variables. Multiple Assignment
  • 35. Python Data Types • Variables can hold values of different data types. • Python is a dynamically typed language hence we need not define the type of the variable while declaring it. • The interpreter implicitly binds the value with its type.
  • 36. Python Data Types • python enables us to check the type of the variable used in the program. • Python provides us the type() function which returns the type of the variable passed.
  • 37. Python Data Types Python data types are categorized into two as follows: Mutable Data Types: Data types in python where the value assigned to a variable can be changed Immutable Data Types: Data types in python where the value assigned to a variable cannot be changed
  • 39. Python-Numbers • Number data types store numeric values. • They are immutable data types, means that changing the value of a number data type is not possible. • For example − • var1 = 1 var2 = 10 • You can also delete the reference to a number object by using the del statement. • Del var1
  • 40. Python-Numbers • Python supports four different numerical types − • int (signed integers) − They are often called just integers or ints, are positive or negative whole numbers with no decimal point. • Long (long integers ) − Also called longs, they are integers of unlimited size, written like integers and followed by an uppercase or lowercase L. • float (floating point real values) − Also called floats, they represent real numbers and are written with a decimal point dividing the integer and fractional parts. • complex (complex numbers) − are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number).
  • 41. Number Type Conversion • But sometimes, you need to convert a number explicitly from one type to another to satisfy the requirements of an operator or function parameter. • Type int(x) to convert x to a plain integer. • Type long(x) to convert x to a long integer. • Type float(x) to convert x to a floating-point number. • Type complex(x) to convert x to a complex number with real part x and imaginary part zero. • Type complex(x, y) to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions
  • 43. Strings • Strings are amongst the most popular types in Python. • We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes. • var1 = 'Hello World!‘ • var2 = "Python Programming"
  • 44. Accessing Values in Strings • Python does not support a character type; these are treated as strings of length one, thus also considered a substring. • To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.
  • 45. Updating Strings • You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to its previous value or to a completely different string altogether.
  • 48. Python Lists • Lists are the most versatile of Python's compound data types. • A list contains items separated by commas and enclosed within square brackets ([]). • To some extent, lists are similar to arrays in C. • One difference between them is that all the items belonging to a list can be of different data type.
  • 50. Python Tuples • A tuple is another sequence data type that is similar to the list. • A tuple consists of a number of values separated by commas. • Unlike lists, however, tuples are enclosed within parentheses. • The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, • while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. • Tuples can be thought of as read-only lists.
  • 52. Python Dictionary • A Python dictionary is a mapping of unique keys to values. Dictionaries are mutable, which means they can be changed. • Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).
  • 53. Python Dictionary dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} Print( "dict['Name']: ", dict['Name']) print ("dict['Age']: ", dict['Age'])
  • 54. Dictionary Functions • Len-The method len() gives the total length of the dictionary. • dict = {'Name': 'Zara', 'Age': 7}; • print (len(dict)) • Copy-The method copy() returns a shallow copy of the dictionary. • dict1 = {'Name': 'Zara', 'Age': 7}; • dict2 = dict1.copy() • print "New Dictionary : %s" % str(dict2)
  • 56. • Keys-The method keys() returns a list of all the available keys in the dictionary. • my_dict = {'name':'Jack', 'age': 26} • print "Value : %s" % dict.keys() • Values-The method values() returns a list of all the values available in a given dictionary. • print "Value : %s" % dict.values()
  • 58. Set in Python • A set is an unordered collection of items. • Every element is unique (no duplicates) and must be immutable (which cannot be changed). • my_set = {1, 2, 3} • print(my_set)
  • 59. Change a set in Python • Sets are mutable. But since they are unordered, indexing have no meaning. • We can add single element using the add() method and multiple elements using the update() method. • The update() method can take tuples, lists, strings or other sets as its argument. In all cases, duplicates are avoided.
  • 61. Remove elements from a set • A particular item can be removed from set using methods, discard() and remove(). • The only difference between the two is that, while using discard() if the item does not exist in the set, it remains unchanged. • But remove() will raise an error in such condition. • my_set.discard(4) • print(my_set) • my_set.remove(4)