SlideShare a Scribd company logo
Python Variables
Python Variables - Assign Multiple Values
Many Values to Multiple Variables-
Python allows you to assign values to multiple variables in one
line:
Exampler own Python Server
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Note: Make sure the number of variables matches
the number of values, or else you will get an error.
One Value to Multiple Variables
And you can assign the same value to multiple variables
in one line:
Example
x = y = z = "Orange"
print(x)
print(y)
print(z)
Unpack a Collection
If you have a collection of values in a list, tuple etc.
Python allows you to extract the values into variables.
This is called unpacking.
Example:-
Unpack a list:
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Output Variables
ExamplewnPython Serve
x = "Python is awesome"
print(x)
In the print() function you output multiple
variables, separated by a comma:
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
The Python print() function is often used to
output variables.
You can also use the + operator to output multiple varible:
x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
For numbers, the + character works as a mathematical
operator:
x = 5
y = 10
print(x + y)
In the print() function when you try to combine a string and a number
with the + operator, python will give you an error:
x = 5
y = "John"
print(x + y)
This will given an error. Try this yourself!
The best way to output multiple variable in the
print() function is to separate them with commas ,
which even support different data types:
x = 5
y = "John"
print(x, y)
Exercise:
Create a variable name carname and assign the value Volvo to it
To Be Continued……

More Related Content

Similar to Python Variables.pptx

Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Python
PythonPython
Python programing
Python programingPython programing
Python programing
hamzagame
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
ShwetaAggarwal56
 
iPython
iPythoniPython
iPython
Aman Lalpuria
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
NawalKishore38
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
srxerox
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 
Revision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docRevision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.doc
SrikrishnaVundavalli
 
Python Basics
Python Basics Python Basics
Python Basics
Adheetha O. V
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. Coding
TanishqGosavi
 
List.ppt
List.pptList.ppt
List.ppt
VIBITHAS3
 
Python Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptxPython Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptx
MuhammadUmar890FETBS
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
RohitSindhu10
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
AkashdeepBhattacharj1
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
Sharath Ankrajegowda
 

Similar to Python Variables.pptx (20)

Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python
PythonPython
Python
 
Python programing
Python programingPython programing
Python programing
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
iPython
iPythoniPython
iPython
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
Revision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docRevision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.doc
 
Python Basics
Python Basics Python Basics
Python Basics
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. Coding
 
List.ppt
List.pptList.ppt
List.ppt
 
Foundations of Programming Part II
Foundations of Programming Part IIFoundations of Programming Part II
Foundations of Programming Part II
 
Python Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptxPython Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptx
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 

More from adityakumawat625

Data Analytics.pptx
Data Analytics.pptxData Analytics.pptx
Data Analytics.pptx
adityakumawat625
 
Python Tuples.pptx
Python Tuples.pptxPython Tuples.pptx
Python Tuples.pptx
adityakumawat625
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
adityakumawat625
 
Python Lists.pptx
Python Lists.pptxPython Lists.pptx
Python Lists.pptx
adityakumawat625
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptx
adityakumawat625
 
Python comments and variables.pptx
Python comments and variables.pptxPython comments and variables.pptx
Python comments and variables.pptx
adityakumawat625
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
adityakumawat625
 
python intro and installation.pptx
python intro and installation.pptxpython intro and installation.pptx
python intro and installation.pptx
adityakumawat625
 
sql datatypes.pptx
sql datatypes.pptxsql datatypes.pptx
sql datatypes.pptx
adityakumawat625
 
sql_operators.pptx
sql_operators.pptxsql_operators.pptx
sql_operators.pptx
adityakumawat625
 
SQL Tables.pptx
SQL Tables.pptxSQL Tables.pptx
SQL Tables.pptx
adityakumawat625
 
create database.pptx
create database.pptxcreate database.pptx
create database.pptx
adityakumawat625
 
SQL syntax.pptx
SQL syntax.pptxSQL syntax.pptx
SQL syntax.pptx
adityakumawat625
 
Introduction to SQL.pptx
Introduction to SQL.pptxIntroduction to SQL.pptx
Introduction to SQL.pptx
adityakumawat625
 

More from adityakumawat625 (14)

Data Analytics.pptx
Data Analytics.pptxData Analytics.pptx
Data Analytics.pptx
 
Python Tuples.pptx
Python Tuples.pptxPython Tuples.pptx
Python Tuples.pptx
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
 
Python Lists.pptx
Python Lists.pptxPython Lists.pptx
Python Lists.pptx
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptx
 
Python comments and variables.pptx
Python comments and variables.pptxPython comments and variables.pptx
Python comments and variables.pptx
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
python intro and installation.pptx
python intro and installation.pptxpython intro and installation.pptx
python intro and installation.pptx
 
sql datatypes.pptx
sql datatypes.pptxsql datatypes.pptx
sql datatypes.pptx
 
sql_operators.pptx
sql_operators.pptxsql_operators.pptx
sql_operators.pptx
 
SQL Tables.pptx
SQL Tables.pptxSQL Tables.pptx
SQL Tables.pptx
 
create database.pptx
create database.pptxcreate database.pptx
create database.pptx
 
SQL syntax.pptx
SQL syntax.pptxSQL syntax.pptx
SQL syntax.pptx
 
Introduction to SQL.pptx
Introduction to SQL.pptxIntroduction to SQL.pptx
Introduction to SQL.pptx
 

Recently uploaded

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 

Python Variables.pptx

  • 2. Python Variables - Assign Multiple Values Many Values to Multiple Variables- Python allows you to assign values to multiple variables in one line: Exampler own Python Server x, y, z = "Orange", "Banana", "Cherry" print(x) print(y) print(z) Note: Make sure the number of variables matches the number of values, or else you will get an error.
  • 3. One Value to Multiple Variables And you can assign the same value to multiple variables in one line: Example x = y = z = "Orange" print(x) print(y) print(z)
  • 4. Unpack a Collection If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking. Example:- Unpack a list: fruits = ["apple", "banana", "cherry"] x, y, z = fruits print(x) print(y) print(z)
  • 5. Output Variables ExamplewnPython Serve x = "Python is awesome" print(x) In the print() function you output multiple variables, separated by a comma: x = "Python" y = "is" z = "awesome" print(x, y, z) The Python print() function is often used to output variables.
  • 6. You can also use the + operator to output multiple varible: x = "Python " y = "is " z = "awesome" print(x + y + z) For numbers, the + character works as a mathematical operator: x = 5 y = 10 print(x + y)
  • 7. In the print() function when you try to combine a string and a number with the + operator, python will give you an error: x = 5 y = "John" print(x + y) This will given an error. Try this yourself! The best way to output multiple variable in the print() function is to separate them with commas , which even support different data types: x = 5 y = "John" print(x, y)
  • 8. Exercise: Create a variable name carname and assign the value Volvo to it To Be Continued……