Introduction to python

Ayshwarya Baburam
Ayshwarya BaburamAssitant professor at kristu jayanti college um kristu jayanti college
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
1 von 62

Recomendados

Introduction to the basics of Python programming (part 1) von
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
1.3K views36 Folien
Python Programming ppt von
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
3.8K views61 Folien
Let’s Learn Python An introduction to Python von
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
3.6K views62 Folien
Introduction to python programming von
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
2.7K views115 Folien
Python Tutorial Part 1 von
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1Haitham El-Ghareeb
3.8K views76 Folien

Más contenido relacionado

Was ist angesagt?

Presentation on python von
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
1.9K views16 Folien
Python programming | Fundamentals of Python programming von
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
881 views12 Folien
Fundamentals of Python Programming von
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
9.8K views135 Folien
Python ppt von
Python pptPython ppt
Python pptMohita Pandey
3.7K views53 Folien
Python (basic) von
Python (basic)Python (basic)
Python (basic)Sabyasachi Moitra
2.7K views104 Folien
Basic Python Programming: Part 01 and Part 02 von
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
2.7K views121 Folien

Was ist angesagt?(20)

Presentation on python von william john
Presentation on pythonPresentation on python
Presentation on python
william john1.9K views
Python programming | Fundamentals of Python programming von KrishnaMildain
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
KrishnaMildain881 views
Fundamentals of Python Programming von Kamal Acharya
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya9.8K views
Basic Python Programming: Part 01 and Part 02 von Fariz Darari
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari2.7K views
Introduction to Python von amiable_indian
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian36.8K views
Python - An Introduction von Swarit Wadhe
Python - An IntroductionPython - An Introduction
Python - An Introduction
Swarit Wadhe4.4K views
Python 3 Programming Language von Tahani Al-Manie
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie11.5K views
Introduction to Python von Nowell Strite
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite167.9K views
Python Basics | Python Tutorial | Edureka von Edureka!
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
Edureka!811 views
Python Programming Language | Python Classes | Python Tutorial | Python Train... von Edureka!
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!4.9K views

Similar a Introduction to python

Python-Basics.pptx von
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptxTamalSengupta8
3 views98 Folien
Python Programming 1.pptx von
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptxFrancis Densil Raj
27 views258 Folien
1. python programming von
1. python programming1. python programming
1. python programmingsreeLekha51
222 views35 Folien
introduction to python von
 introduction to python introduction to python
introduction to pythonJincy Nelson
142 views47 Folien
Python Programming von
Python ProgrammingPython Programming
Python ProgrammingSaravanan T.M
642 views131 Folien
Chapter7-Introduction to Python.pptx von
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxlemonchoos
14 views47 Folien

Similar a Introduction to python(20)

1. python programming von sreeLekha51
1. python programming1. python programming
1. python programming
sreeLekha51222 views
introduction to python von Jincy Nelson
 introduction to python introduction to python
introduction to python
Jincy Nelson142 views
Chapter7-Introduction to Python.pptx von lemonchoos
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
lemonchoos14 views
Python for katana von kedar nath
Python for katanaPython for katana
Python for katana
kedar nath11.5K views
Learn Python The Hard Way Presentation von Amira ElSharkawy
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy912 views
presentation_python_7_1569170870_375360.pptx von ansariparveen06
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
Zero to Hero - Introduction to Python3 von Chariza Pladin
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
Chariza Pladin7.6K views

Último

Microsoft Power Platform.pptx von
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
47 views38 Folien
Black and White Modern Science Presentation.pptx von
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 Folien
Web Dev - 1 PPT.pdf von
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdfgdsczhcet
55 views45 Folien
handbook for web 3 adoption.pdf von
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdfLiveplex
19 views16 Folien
Spesifikasi Lengkap ASUS Vivobook Go 14 von
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14Dot Semarang
35 views1 Folie
The details of description: Techniques, tips, and tangents on alternative tex... von
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 Folien

Último(20)

Black and White Modern Science Presentation.pptx von maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
Web Dev - 1 PPT.pdf von gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
handbook for web 3 adoption.pdf von Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
Spesifikasi Lengkap ASUS Vivobook Go 14 von Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
The details of description: Techniques, tips, and tangents on alternative tex... von BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
STPI OctaNE CoE Brochure.pdf von madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Special_edition_innovator_2023.pdf von WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... von James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson33 views
HTTP headers that make your website go faster - devs.gent November 2023 von Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn19 views
Data-centric AI and the convergence of data and model engineering: opportunit... von Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
Attacking IoT Devices from a Web Perspective - Linux Day von Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 von Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Voice Logger - Telephony Integration Solution at Aegis von Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker26 views

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)