SlideShare a Scribd company logo
Jagannath Institute of Management Sciences
Vasant Kunj-II, New Delhi - 110070
Subject Name: BVITSD 205 : Programming And
Problem Solving Though PYTHON
Department of Information Technology
Created By: Dr. Arpana Chaturvedi
@Dr. Arpana Chaturvedi
Subject: BVITSD 205 : PROGRAMMING AND
PROBLEM SOLVING THOUGH PYTHON
Topic: Unit II- Python Variables and Data Types
@Dr. Arpana Chaturvedi
Unit-II Python Variables and Data Types
@Dr. Arpana Chaturvedi
An Introduction to
Variables
Data Types
Types
Conversion
Local and
Global
Variables
Variable Naming
Rules
Assigning
Variables
Numbers
Strings
int()
float()
Local
Variables
Global
Variables
str()
bool()
list()
List
Tuple
Dictionaries
Multiple
Variables
Deleting
Variables
Unit-II Python Variables
@Dr. Arpana Chaturvedi
Python Variables
X=45
Type=Integer
name=“ JIMS ”
Type=String
nums=[ 1,3,5,7 ] Type=Lists
45
x
“ JIMS ”
name
[ 1,3,5,7 ]
nums
▰ A variable is a container for a value. It can be assigned a name, you can use it to
refer to it later in the program.
▰ Based on the value assigned, the interpreter decides its data type. You can always
store a different type in a variable.
Unit-II Python Variable Naming Convention
There are certain rules to what you can name a variable(called an identifier).
▰ Python variables can only begin with a letter(A-Z/a-z) or an underscore(_).
▰ The rest of the identifier may contain letters(A-Z/a-z), underscores(_), and
numbers(0-9).
▰ Python is case-sensitive, and so are Python identifiers. Name and name are two
different identifiers.
▰ Reserved words (keywords) cannot be used as identifier names.
@Dr. Arpana Chaturvedi
Unit-II Python Variables Examples
@Dr. Arpana Chaturvedi
Unit-II 2. Assigning and Reassigning Python
Variables
▰ To assign a value to Python variables, you don‟t need to declare its type.
▰ You name it according to the rules of variable naming convention, and type the
value after the equal sign(=).
@Dr. Arpana Chaturvedi
You can‟t put the identifier on the right-hand side of the equal sign, though. The
following code causes an error.
Neither can you assign Python variables to a keyword.
Unit-II 3. Multiple Assignment
▰ You can assign values to multiple Python variables in one statement.
▰ Or you can assign the same value to multiple Python variables.
@Dr. Arpana Chaturvedi
Unit-II 4. Swapping Python Variables
▰ Swapping means interchanging values. To swap Python variables, you don‟t need
to do much.
@Dr. Arpana Chaturvedi
Unit-II 4.Deleting Python Variables
▰ You can also delete Python variables using the keyword „del‟.
@Dr. Arpana Chaturvedi
Unit-II Python Datatypes
▰ Although we don‟t have to declare a type for Python variables, a value does have a
type. This information is vital to the interpreter.
▰ Python supports the following data types.
1. Python Numbers
2. Strings
3. Python Lists
4. Python Tuples
5. Dictionaries
7. Sets
@Dr. Arpana Chaturvedi
Unit-II 1. Python Numbers
▰ There are four numeric Python data types.
a. int
b. float
c. long
d. complex
@Dr. Arpana Chaturvedi
Unit-II 1. Python Numbers
a. int
▰ int stands for integer. This Python Data Type holds signed integers. We can use the
type() function to find which class it belongs to.
@Dr. Arpana Chaturvedi
An integer can be of any length, with the only limitation being the available memory.
Unit-II 1. Python Numbers
b. float
▰ This Python Data Type holds floating-point real values. An int can only store the
number 3, but float can store 3.25 if you want.
@Dr. Arpana Chaturvedi
c. long
This Python Data type holds a long integer of unlimited length. But this construct does
not exist in Python 3.x.
Unit-II 1. Python Numbers
d. complex
This Python Data type holds a complex number. A complex number looks like this: a+bj
Here, a and b are the real parts of the number, and j is imaginary.
@Dr. Arpana Chaturvedi
Use the isinstance() function to tell if Python variables belong to a particular class. It
takes two parameters- the variable/value, and the class.
Unit-II 2. Strings
▰ A String is a sequence of characters. Python does not have a char data type, unlike
C++ or Java. You can delimit a string using single quotes or double-quotes.
@Dr. Arpana Chaturvedi
a. Spanning a String Across Lines
▰ To span a string across multiple lines, you can use triple quotes.
As you can see, the quotes
preserved the formatting (n is the
escape sequence for newline, t is
for tab).
Unit-II 2. Strings
@Dr. Arpana Chaturvedi
b. Displaying Part of a String
You can display a character from a string using its index in the string. Remember,
indexing starts with 0.
You can also display a burst of characters in a string using the slicing operator [].
This prints the characters from 0 to 5.
Unit-II 2. Strings
@Dr. Arpana Chaturvedi
c. String Formatters
String formatters allow us to print characters and values at once. You can use the %
operator.
Or you can use the format method.
A third option is to use f-strings.
Unit-II 2. Strings
@Dr. Arpana Chaturvedi
d. String Concatenation
You can concatenate(join) strings.
However, you cannot concatenate values of different types.
Unit-II 3. Python Lists
@Dr. Arpana Chaturvedi
A list is a collection of values. Remember, it may contain different types of values.
To define a list, you must put values separated with commas in square brackets. You
don‟t need to declare a type for a list either.
a. Slicing a List
You can slice a list the way you‟d slice a string- with the slicing operator.
Indexing for a list begins with 0, like for a string. A Python doesn‟t have arrays.
Unit-II 3. Python Lists
@Dr. Arpana Chaturvedi
c. Length of a List
Python supports an inbuilt function to calculate the length of a list.
c. Reassigning Elements of a List
A list is mutable. This means that you can reassign elements later on.
Unit-II 3. Python Lists
@Dr. Arpana Chaturvedi
d. Iterating on the List
To iterate over the list we can use the for loop. By iterating, we can access each
element one by one which is very helpful when we need to perform some operations
on each element of list.
Unit-II 3. Python Lists
@Dr. Arpana Chaturvedi
e. Multidimensional Lists
A list may have more than one dimension.
Unit-II Python Tuples
▰ A tuple is like a list. You declare it using parentheses instead.
@Dr. Arpana Chaturvedi
a. Accessing and Slicing a Tuple
You access a tuple the same way as you‟d access a list. The same goes for slicing
it.
Unit-II Python Tuples
@Dr. Arpana Chaturvedi
b. A tuple is Immutable
Python tuple is immutable. Once declared, you can‟t change its size or elements.
Unit-II 5. Dictionaries
▰ A dictionary holds key-value pairs. Declare it in curly braces, with pairs separated
by commas. Separate keys and values by a colon(:).
▰ The type() function works with dictionaries too.
@Dr. Arpana Chaturvedi
Unit-II 5. Dictionaries
▰ a. Accessing a Value
▰ To access a value, you mention the key in square brackets.
▰ b. Reassigning Elements
▰ You can reassign a value to a key.
@Dr. Arpana Chaturvedi
Unit-II 5. Dictionaries
▰ c. List of Keys
▰ Use the keys() function to get a list of keys in the dictionary.
@Dr. Arpana Chaturvedi
Unit-II 6. bool
▰ A Boolean value can be True or False.
@Dr. Arpana Chaturvedi
Unit-II 7. Sets
▰ 7. Sets
▰ A set can have a list of values. Define it using curly braces.
@Dr. Arpana Chaturvedi
It returns only one instance of any value present more than once.
However, a set is unordered, so it doesn‟t support indexing.
Unit-II 7. Sets
▰ 7. Sets
▰ Also, it is mutable. You can change its elements or add more. Use the add() and
remove() methods to do so.
@Dr. Arpana Chaturvedi
Unit-II Python Type Conversion
▰ Since Python is dynamically-typed, you may want to convert a value into another
type. Python supports a list of functions for the same.
▰ 1. int()
▰ It converts the value into an int.
@Dr. Arpana Chaturvedi
Notice how it truncated 0.7 instead of rounding the number off to 4. You can also turn
a Boolean into an int.
Unit-II Python Type Conversion
▰ However, you cannot turn a string into an int. It throws an error.
@Dr. Arpana Chaturvedi
 However, if the string has only numbers, then you can.
Unit-II Python Type Conversion
▰ 2. float()
▰ It converts the value into a float.
@Dr. Arpana Chaturvedi
However, this number works even without the float() function.
You can also use ‘e’ to denote an exponential number.
Unit-II Python Type Conversion
▰ 3. str()
▰ It converts the value into a string.
@Dr. Arpana Chaturvedi
Unit-II Python Type Conversion
▰ 4. bool()
▰ It converts the value into a Boolean.
@Dr. Arpana Chaturvedi
Unit-II 5. Python Sets
▰ 5. set()
▰ It converts the value into a set.
@Dr. Arpana Chaturvedi
Unit-II 6. Python list()
▰ 6. list()
▰ It converts the value into a list.
@Dr. Arpana Chaturvedi
Unit-II 7. Python tuple
▰ 7. tuple()
▰ It converts the value into a tuple.
@Dr. Arpana Chaturvedi
You can try your own combinations. Also
try composite functions.
Unit-II Python Local and Global Variables
▰ 1. Python Local Variables
▰ When you declare a variable in a function, class, or so, it is only visible in that
scope. If you call it outside of that scope, you get an „undefined‟ error.
@Dr. Arpana Chaturvedi
Here, the variable num is local to function func1().
Unit-II Python Local and Global Variables
▰ 2. Global Variables
▰ When you declare a variable outside any context/scope, it is visible in the whole
program.
@Dr. Arpana Chaturvedi
Unit-II Python Local and Global Variables
▰ 2. Global Variables
▰ You can use the „global‟ keyword when you want to treat a variable as global in a
local scope.
@Dr. Arpana Chaturvedi
Unit-II Python Variables Assignment
▰ What are variables and data types in Python?
▰ What is type () in Python?
▰ What are Local and Global variables in Python?
▰ Explain various naming rules for Python Variables.
▰ How to display part of a string?
@Dr. Arpana Chaturvedi
Thank You !!

More Related Content

PDF
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
PDF
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
PDF
E-Notes_3720_Content_Document_20250107032323PM.pdf
PPTX
2. Values and Data types in Python.pptx
PPTX
Chapter - 2.pptx
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
PPT
Python - Module 1.ppt
PPTX
Python 3 Programming Language
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
2. Values and Data types in Python.pptx
Chapter - 2.pptx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
Python - Module 1.ppt
Python 3 Programming Language

Similar to Unit 2 Part 1.2 Data Types.pdf (20)

PPT
UNIT II_python Programming_aditya College
PDF
Python Tutorial Questions part-1
PPTX
Basic of Python- Hands on Session
PDF
Python_Unit_1.pdf
PPTX
Python For Data Science.pptx
PPT
Unit 2 python
PDF
4. Data Handling computer shcience pdf s
PPTX
Python basics
PDF
Zero to Hero - Introduction to Python3
PPTX
Introduction to Python for Data Science and Machine Learning
PDF
Free Complete Python - A step towards Data Science
PPTX
trisha comp ppt.pptx
PDF
13- Data and Its Types presentation kafss
PPTX
Python (Data Analysis) cleaning and visualize
PPTX
python programming control structures.pptx
PPTX
Data Types In Python.pptx
PPTX
PYTHON PPT.pptx python is very useful for day to day life
PPTX
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
PPTX
introduction to python,datatypes,operators
PDF
"Automata Basics and Python Applications"
UNIT II_python Programming_aditya College
Python Tutorial Questions part-1
Basic of Python- Hands on Session
Python_Unit_1.pdf
Python For Data Science.pptx
Unit 2 python
4. Data Handling computer shcience pdf s
Python basics
Zero to Hero - Introduction to Python3
Introduction to Python for Data Science and Machine Learning
Free Complete Python - A step towards Data Science
trisha comp ppt.pptx
13- Data and Its Types presentation kafss
Python (Data Analysis) cleaning and visualize
python programming control structures.pptx
Data Types In Python.pptx
PYTHON PPT.pptx python is very useful for day to day life
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
introduction to python,datatypes,operators
"Automata Basics and Python Applications"
Ad

More from Arpana Awasthi (12)

PDF
Unit 5 Part 1 Macros
PDF
Introduction To Python.pdf
PDF
Unit 2 Part 1 POLYMORPHISM.pdf
PDF
Unit 2 Part 1 Constructors.pdf
PDF
Eclipse - GUI Palette
PPTX
Introduction to Eclipse
PDF
Arrays 2 Dimensional Unit 2 Part 1.pdf
PDF
Arrays Fundamentals Unit II
PDF
Machine Learning: Need of Machine Learning, Its Challenges and its Applications
PDF
File Handling in C Part I
PDF
Programming language
PDF
Role of machine learning in detection, prevention and treatment of cancer
Unit 5 Part 1 Macros
Introduction To Python.pdf
Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 Constructors.pdf
Eclipse - GUI Palette
Introduction to Eclipse
Arrays 2 Dimensional Unit 2 Part 1.pdf
Arrays Fundamentals Unit II
Machine Learning: Need of Machine Learning, Its Challenges and its Applications
File Handling in C Part I
Programming language
Role of machine learning in detection, prevention and treatment of cancer
Ad

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A comparative analysis of optical character recognition models for extracting...
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...

Unit 2 Part 1.2 Data Types.pdf

  • 1. Jagannath Institute of Management Sciences Vasant Kunj-II, New Delhi - 110070 Subject Name: BVITSD 205 : Programming And Problem Solving Though PYTHON Department of Information Technology Created By: Dr. Arpana Chaturvedi @Dr. Arpana Chaturvedi
  • 2. Subject: BVITSD 205 : PROGRAMMING AND PROBLEM SOLVING THOUGH PYTHON Topic: Unit II- Python Variables and Data Types @Dr. Arpana Chaturvedi
  • 3. Unit-II Python Variables and Data Types @Dr. Arpana Chaturvedi An Introduction to Variables Data Types Types Conversion Local and Global Variables Variable Naming Rules Assigning Variables Numbers Strings int() float() Local Variables Global Variables str() bool() list() List Tuple Dictionaries Multiple Variables Deleting Variables
  • 4. Unit-II Python Variables @Dr. Arpana Chaturvedi Python Variables X=45 Type=Integer name=“ JIMS ” Type=String nums=[ 1,3,5,7 ] Type=Lists 45 x “ JIMS ” name [ 1,3,5,7 ] nums ▰ A variable is a container for a value. It can be assigned a name, you can use it to refer to it later in the program. ▰ Based on the value assigned, the interpreter decides its data type. You can always store a different type in a variable.
  • 5. Unit-II Python Variable Naming Convention There are certain rules to what you can name a variable(called an identifier). ▰ Python variables can only begin with a letter(A-Z/a-z) or an underscore(_). ▰ The rest of the identifier may contain letters(A-Z/a-z), underscores(_), and numbers(0-9). ▰ Python is case-sensitive, and so are Python identifiers. Name and name are two different identifiers. ▰ Reserved words (keywords) cannot be used as identifier names. @Dr. Arpana Chaturvedi
  • 6. Unit-II Python Variables Examples @Dr. Arpana Chaturvedi
  • 7. Unit-II 2. Assigning and Reassigning Python Variables ▰ To assign a value to Python variables, you don‟t need to declare its type. ▰ You name it according to the rules of variable naming convention, and type the value after the equal sign(=). @Dr. Arpana Chaturvedi You can‟t put the identifier on the right-hand side of the equal sign, though. The following code causes an error. Neither can you assign Python variables to a keyword.
  • 8. Unit-II 3. Multiple Assignment ▰ You can assign values to multiple Python variables in one statement. ▰ Or you can assign the same value to multiple Python variables. @Dr. Arpana Chaturvedi
  • 9. Unit-II 4. Swapping Python Variables ▰ Swapping means interchanging values. To swap Python variables, you don‟t need to do much. @Dr. Arpana Chaturvedi
  • 10. Unit-II 4.Deleting Python Variables ▰ You can also delete Python variables using the keyword „del‟. @Dr. Arpana Chaturvedi
  • 11. Unit-II Python Datatypes ▰ Although we don‟t have to declare a type for Python variables, a value does have a type. This information is vital to the interpreter. ▰ Python supports the following data types. 1. Python Numbers 2. Strings 3. Python Lists 4. Python Tuples 5. Dictionaries 7. Sets @Dr. Arpana Chaturvedi
  • 12. Unit-II 1. Python Numbers ▰ There are four numeric Python data types. a. int b. float c. long d. complex @Dr. Arpana Chaturvedi
  • 13. Unit-II 1. Python Numbers a. int ▰ int stands for integer. This Python Data Type holds signed integers. We can use the type() function to find which class it belongs to. @Dr. Arpana Chaturvedi An integer can be of any length, with the only limitation being the available memory.
  • 14. Unit-II 1. Python Numbers b. float ▰ This Python Data Type holds floating-point real values. An int can only store the number 3, but float can store 3.25 if you want. @Dr. Arpana Chaturvedi c. long This Python Data type holds a long integer of unlimited length. But this construct does not exist in Python 3.x.
  • 15. Unit-II 1. Python Numbers d. complex This Python Data type holds a complex number. A complex number looks like this: a+bj Here, a and b are the real parts of the number, and j is imaginary. @Dr. Arpana Chaturvedi Use the isinstance() function to tell if Python variables belong to a particular class. It takes two parameters- the variable/value, and the class.
  • 16. Unit-II 2. Strings ▰ A String is a sequence of characters. Python does not have a char data type, unlike C++ or Java. You can delimit a string using single quotes or double-quotes. @Dr. Arpana Chaturvedi a. Spanning a String Across Lines ▰ To span a string across multiple lines, you can use triple quotes. As you can see, the quotes preserved the formatting (n is the escape sequence for newline, t is for tab).
  • 17. Unit-II 2. Strings @Dr. Arpana Chaturvedi b. Displaying Part of a String You can display a character from a string using its index in the string. Remember, indexing starts with 0. You can also display a burst of characters in a string using the slicing operator []. This prints the characters from 0 to 5.
  • 18. Unit-II 2. Strings @Dr. Arpana Chaturvedi c. String Formatters String formatters allow us to print characters and values at once. You can use the % operator. Or you can use the format method. A third option is to use f-strings.
  • 19. Unit-II 2. Strings @Dr. Arpana Chaturvedi d. String Concatenation You can concatenate(join) strings. However, you cannot concatenate values of different types.
  • 20. Unit-II 3. Python Lists @Dr. Arpana Chaturvedi A list is a collection of values. Remember, it may contain different types of values. To define a list, you must put values separated with commas in square brackets. You don‟t need to declare a type for a list either. a. Slicing a List You can slice a list the way you‟d slice a string- with the slicing operator. Indexing for a list begins with 0, like for a string. A Python doesn‟t have arrays.
  • 21. Unit-II 3. Python Lists @Dr. Arpana Chaturvedi c. Length of a List Python supports an inbuilt function to calculate the length of a list. c. Reassigning Elements of a List A list is mutable. This means that you can reassign elements later on.
  • 22. Unit-II 3. Python Lists @Dr. Arpana Chaturvedi d. Iterating on the List To iterate over the list we can use the for loop. By iterating, we can access each element one by one which is very helpful when we need to perform some operations on each element of list.
  • 23. Unit-II 3. Python Lists @Dr. Arpana Chaturvedi e. Multidimensional Lists A list may have more than one dimension.
  • 24. Unit-II Python Tuples ▰ A tuple is like a list. You declare it using parentheses instead. @Dr. Arpana Chaturvedi a. Accessing and Slicing a Tuple You access a tuple the same way as you‟d access a list. The same goes for slicing it.
  • 25. Unit-II Python Tuples @Dr. Arpana Chaturvedi b. A tuple is Immutable Python tuple is immutable. Once declared, you can‟t change its size or elements.
  • 26. Unit-II 5. Dictionaries ▰ A dictionary holds key-value pairs. Declare it in curly braces, with pairs separated by commas. Separate keys and values by a colon(:). ▰ The type() function works with dictionaries too. @Dr. Arpana Chaturvedi
  • 27. Unit-II 5. Dictionaries ▰ a. Accessing a Value ▰ To access a value, you mention the key in square brackets. ▰ b. Reassigning Elements ▰ You can reassign a value to a key. @Dr. Arpana Chaturvedi
  • 28. Unit-II 5. Dictionaries ▰ c. List of Keys ▰ Use the keys() function to get a list of keys in the dictionary. @Dr. Arpana Chaturvedi
  • 29. Unit-II 6. bool ▰ A Boolean value can be True or False. @Dr. Arpana Chaturvedi
  • 30. Unit-II 7. Sets ▰ 7. Sets ▰ A set can have a list of values. Define it using curly braces. @Dr. Arpana Chaturvedi It returns only one instance of any value present more than once. However, a set is unordered, so it doesn‟t support indexing.
  • 31. Unit-II 7. Sets ▰ 7. Sets ▰ Also, it is mutable. You can change its elements or add more. Use the add() and remove() methods to do so. @Dr. Arpana Chaturvedi
  • 32. Unit-II Python Type Conversion ▰ Since Python is dynamically-typed, you may want to convert a value into another type. Python supports a list of functions for the same. ▰ 1. int() ▰ It converts the value into an int. @Dr. Arpana Chaturvedi Notice how it truncated 0.7 instead of rounding the number off to 4. You can also turn a Boolean into an int.
  • 33. Unit-II Python Type Conversion ▰ However, you cannot turn a string into an int. It throws an error. @Dr. Arpana Chaturvedi  However, if the string has only numbers, then you can.
  • 34. Unit-II Python Type Conversion ▰ 2. float() ▰ It converts the value into a float. @Dr. Arpana Chaturvedi However, this number works even without the float() function. You can also use ‘e’ to denote an exponential number.
  • 35. Unit-II Python Type Conversion ▰ 3. str() ▰ It converts the value into a string. @Dr. Arpana Chaturvedi
  • 36. Unit-II Python Type Conversion ▰ 4. bool() ▰ It converts the value into a Boolean. @Dr. Arpana Chaturvedi
  • 37. Unit-II 5. Python Sets ▰ 5. set() ▰ It converts the value into a set. @Dr. Arpana Chaturvedi
  • 38. Unit-II 6. Python list() ▰ 6. list() ▰ It converts the value into a list. @Dr. Arpana Chaturvedi
  • 39. Unit-II 7. Python tuple ▰ 7. tuple() ▰ It converts the value into a tuple. @Dr. Arpana Chaturvedi You can try your own combinations. Also try composite functions.
  • 40. Unit-II Python Local and Global Variables ▰ 1. Python Local Variables ▰ When you declare a variable in a function, class, or so, it is only visible in that scope. If you call it outside of that scope, you get an „undefined‟ error. @Dr. Arpana Chaturvedi Here, the variable num is local to function func1().
  • 41. Unit-II Python Local and Global Variables ▰ 2. Global Variables ▰ When you declare a variable outside any context/scope, it is visible in the whole program. @Dr. Arpana Chaturvedi
  • 42. Unit-II Python Local and Global Variables ▰ 2. Global Variables ▰ You can use the „global‟ keyword when you want to treat a variable as global in a local scope. @Dr. Arpana Chaturvedi
  • 43. Unit-II Python Variables Assignment ▰ What are variables and data types in Python? ▰ What is type () in Python? ▰ What are Local and Global variables in Python? ▰ Explain various naming rules for Python Variables. ▰ How to display part of a string? @Dr. Arpana Chaturvedi