SlideShare a Scribd company logo
Swipe
Python - Variable Types
Variables are nothing but reserved memory
locations to store values.
This means that when you create a variable you
reserve some space in memory.
Based on the data type of a variable, the interpreter
allocates memory and decides what can be stored
in the reserved memory.
Therefore, by assigning different data types to
variables, you can store integers, decimals or
characters in these variables.
Python - Variable Types
Python variables do not need explicit declaration to
reserve memory space.
The declaration happens automatically when you
assign a value to a variable.
The equal sign (=) is used to assign values to
variables.
Assigning Values to Variables
The operand to the left of the = operator is the
name of the variable and the operand to the right
of the = operator is the value stored in the variable.
For example −
#!/usr/bin/python
counter = 100 # An integer assignment
miles = 1000.0 # A floating point
name = "John" # A stringprint counter
print miles
print name
Here, 100, 1000.0 and "John" are the values assigned
to counter, miles, and name variables, respectively.
This produces the following result −
100
1000.0
John
Python allows you to assign a single value to several
variables simultaneously.
For example −
a = b = c = 1
Here, an integer object is created with the value 1,
and all three variables are assigned to the same
memory location. You can also assign multiple
objects to multiple variables.
For example −
a,b,c = 1,2,"john"
Here, two integer objects with values 1 and 2 are
assigned to variables a and b respectively, and one
string object with the value "john" is assigned to the
variable c
Multiple Assignment
The data stored in memory can be of many types.
For example, a person's age is stored as a numeric
value and his or her address is stored as
alphanumeric characters.
Python has various standard data types that are
used to define the operations possible on them and
the storage method for each of them.
Python has five standard data types −
Numbers
String
List
Tuple
Dictionary
Standard Data Types
Sometimes, you may need to perform conversions
between the built-in types.
To convert between types, you simply use the type
name as a function.
There are several built-in functions to perform
conversion from one data type to another.
These functions return a new object representing
the converted value.
Data Type Conversion
int(x [,base])
Converts x to an integer. base specifies the base
if x is a string.
long(x [,base] )
Converts x to a long integer. base specifies the
base if x is a string.
float(x)
Converts x to a floating-point number.
complex(real [,imag])
Creates a complex number.
str(x)
Converts object x to a string representation.
repr(x)
Converts object x to an expression string.
eval(str)
Evaluates a string and returns an object.
oct(x)
Converts an integer to an octal string.
Function & Description
tuple(s)
Converts s to a tuple.
list(s)
Converts s to a list.
set(s)
Converts s to a set.
dict(d)
Creates a dictionary. d must be a sequence of
(key,value) tuples.
frozenset(s)
Converts s to a frozen set.
chr(x)
Converts an integer to a character.
unichr(x)
Converts an integer to a Unicode character.
ord(x)
Converts a single character to its integer value.
hex(x)
Converts an integer to a hexadecimal string.
Python Standard Data Types
Python Operations
Stay Tuned with
Topics for next Post

More Related Content

PPTX
C++ string
PDF
List,tuple,dictionary
PDF
Python programming : Files
PDF
StringTokenizer in java
PPTX
Loops in Python
PDF
Python exception handling
PPTX
Tuple in python
PDF
Python programs - first semester computer lab manual (polytechnics)
C++ string
List,tuple,dictionary
Python programming : Files
StringTokenizer in java
Loops in Python
Python exception handling
Tuple in python
Python programs - first semester computer lab manual (polytechnics)

What's hot (20)

PPT
Specification and complexity - algorithm
PPT
Python List.ppt
PPT
Complexity of Algorithm
PPTX
Functions in c
PPTX
Sparse matrix and its representation data structure
PPTX
Python Datatypes by SujithKumar
PPTX
List in Python
PDF
Immutable vs mutable data types in python
PPT
C++ Arrays
PPT
Trees
PDF
Python programming : Arrays
PPT
DATA STRUCTURE AND ALGORITHMS
PPTX
arrays and pointers
PPTX
POLYNOMIAL ADDITION USING LINKED LIST.pptx
PPTX
List in Python
PPTX
Programming in c Arrays
PPT
Theory of computing
PPTX
Array Introduction One-dimensional array Multidimensional array
PPTX
Strings in c++
PDF
Arrays in python
Specification and complexity - algorithm
Python List.ppt
Complexity of Algorithm
Functions in c
Sparse matrix and its representation data structure
Python Datatypes by SujithKumar
List in Python
Immutable vs mutable data types in python
C++ Arrays
Trees
Python programming : Arrays
DATA STRUCTURE AND ALGORITHMS
arrays and pointers
POLYNOMIAL ADDITION USING LINKED LIST.pptx
List in Python
Programming in c Arrays
Theory of computing
Array Introduction One-dimensional array Multidimensional array
Strings in c++
Arrays in python
Ad

Similar to Python - variable types (20)

PPTX
Lec2 Variables in Python.pptx Funda mentals
PPTX
DATA TYPE IN PYTHON
PPTX
python
PDF
Programming in Civil Engineering_UNIT 2_NOTES
PDF
Python :variable types
PPTX
Python variables and data types.pptx
PDF
The python fundamental introduction part 1
PDF
Python for beginners
DOCX
unit 1.docx
PDF
python- Variables and data types
PPTX
Python 2 with great problems and examples
PPTX
Values and Data types in python
PPTX
2. Values and Data types in Python.pptx
PPTX
Python Programming Essentials - M5 - Variables
PDF
Lecture-2.pdf
PDF
Lecture-2.pdf
PDF
CS-XII Python Fundamentals.pdf
PDF
4. Data Handling computer shcience pdf s
PPTX
009 Data Handling .pptx
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
Lec2 Variables in Python.pptx Funda mentals
DATA TYPE IN PYTHON
python
Programming in Civil Engineering_UNIT 2_NOTES
Python :variable types
Python variables and data types.pptx
The python fundamental introduction part 1
Python for beginners
unit 1.docx
python- Variables and data types
Python 2 with great problems and examples
Values and Data types in python
2. Values and Data types in Python.pptx
Python Programming Essentials - M5 - Variables
Lecture-2.pdf
Lecture-2.pdf
CS-XII Python Fundamentals.pdf
4. Data Handling computer shcience pdf s
009 Data Handling .pptx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
Ad

More from Learnbay Datascience (20)

PDF
Top data science projects
PDF
Python my SQL - create table
PDF
Python my SQL - create database
PDF
Python my sql database connection
PDF
Python - mySOL
PDF
AI - Issues and Terminology
PDF
AI - Fuzzy Logic Systems
PDF
AI - working of an ns
PDF
Artificial Intelligence- Neural Networks
PDF
AI - Robotics
PDF
Applications of expert system
PDF
Components of expert systems
PDF
Artificial intelligence - expert systems
PDF
AI - natural language processing
PDF
Ai popular search algorithms
PDF
AI - Agents & Environments
PDF
Artificial intelligence - research areas
PDF
Artificial intelligence composed
PDF
Artificial intelligence intelligent systems
PDF
Applications of ai
Top data science projects
Python my SQL - create table
Python my SQL - create database
Python my sql database connection
Python - mySOL
AI - Issues and Terminology
AI - Fuzzy Logic Systems
AI - working of an ns
Artificial Intelligence- Neural Networks
AI - Robotics
Applications of expert system
Components of expert systems
Artificial intelligence - expert systems
AI - natural language processing
Ai popular search algorithms
AI - Agents & Environments
Artificial intelligence - research areas
Artificial intelligence composed
Artificial intelligence intelligent systems
Applications of ai

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Cell Types and Its function , kingdom of life
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GDM (1) (1).pptx small presentation for students
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A systematic review of self-coping strategies used by university students to ...
Cell Types and Its function , kingdom of life
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra

Python - variable types

  • 2. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. Python - Variable Types
  • 3. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. Assigning Values to Variables
  • 4. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. For example − #!/usr/bin/python counter = 100 # An integer assignment miles = 1000.0 # A floating point name = "John" # A stringprint counter print miles print name Here, 100, 1000.0 and "John" are the values assigned to counter, miles, and name variables, respectively. This produces the following result − 100 1000.0 John
  • 5. Python allows you to assign a single value to several variables simultaneously. For example − a = b = c = 1 Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example − a,b,c = 1,2,"john" Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively, and one string object with the value "john" is assigned to the variable c Multiple Assignment
  • 6. The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. Python has five standard data types − Numbers String List Tuple Dictionary Standard Data Types
  • 7. Sometimes, you may need to perform conversions between the built-in types. To convert between types, you simply use the type name as a function. There are several built-in functions to perform conversion from one data type to another. These functions return a new object representing the converted value. Data Type Conversion
  • 8. int(x [,base]) Converts x to an integer. base specifies the base if x is a string. long(x [,base] ) Converts x to a long integer. base specifies the base if x is a string. float(x) Converts x to a floating-point number. complex(real [,imag]) Creates a complex number. str(x) Converts object x to a string representation. repr(x) Converts object x to an expression string. eval(str) Evaluates a string and returns an object. oct(x) Converts an integer to an octal string. Function & Description
  • 9. tuple(s) Converts s to a tuple. list(s) Converts s to a list. set(s) Converts s to a set. dict(d) Creates a dictionary. d must be a sequence of (key,value) tuples. frozenset(s) Converts s to a frozen set. chr(x) Converts an integer to a character. unichr(x) Converts an integer to a Unicode character. ord(x) Converts a single character to its integer value. hex(x) Converts an integer to a hexadecimal string.
  • 10. Python Standard Data Types Python Operations Stay Tuned with Topics for next Post