SlideShare a Scribd company logo
Variables in Python Programming
(Elective I)
BCA - 105
2
What is Variable?
 Variable is a name that is used to refer to memory location.
 Python variable is also known as an identifier and used to hold value.
 In Python, we don't need to specify the type of variable because Python is a infer
language and smart enough to get variable type.
 Variable names can be a group of both the letters and digits, but they have to begin with a
letter or an underscore.
 It is recommended to use lowercase letters for the variable name. For example, Rahul and
rahul both are two different variables.
3
Declaring Variable and Assigning Values
 Python does not bind us to declare a variable before
using it in the application. It allows us to create a
variable at the required time.
 We don't need to declare explicitly variable in
Python. When we assign any value to the variable,
that variable is declared automatically.
 The equal (=) operator is used to assign value to a
variable.
 In Python, variables are a symbolic name that is a
reference or pointer to an object. The variables are
used to denote objects by that name.
Example:
a=100
In the below image, the variable a
refers to an integer object.
a 100
4
Object Reference
 It is necessary to understand how the Python interpreter works when we declare a variable.
The process of treating variables is somewhat different from many other programming
languages.
 Python is the highly object-oriented programming language; that's why every data item belongs
to a specific type of class. Consider the following example.
 In the below example print statement, we have created a string object. type() is used to return
the type of the object.
5
Object Identity
 In Python, every created object identifies uniquely in Python.
 Python provides the guaranteed that no two objects will have the same identifier.
 The built-in id() function, is used to identify the object identifier.
6
How to define Variable Names
 Variable names can be any length can have uppercase, lowercase (A to Z, a to z), the digit (0-
9), and underscore character(_). Consider the example of valid variables names.
1.name = "Devansh"
2.age = 20
3.marks = 80.50
1.name = "A"
2.Name = "B"
3.naMe = "C"
4.NAME = "D"
5.n_a_m_e = "E"
6._name = "F"
7.name_ = "G"
8._name_ = "H"
9.na56me = "I"
 In the example, we have declared a few valid variable names
such as name, _name_ , etc. But it is not recommended
because when we try to read code, it may create confusion.
The variable name should be descriptive to make code more
readable.
 The multi-word keywords can be created by the following
method.
1. Camel Case - In the camel case, each word or abbreviation
in the middle of begins with a capital letter. There is no
intervention of whitespace. For example - nameOfStudent,
valueOfVaraible, etc.
2. Pascal Case - It is the same as the Camel Case, but here
the first word is also capital. For example - NameOfStudent,
etc.
3. Snake Case - In the snake case, Words are separated by
the underscore. For example - name_of_student, etc.
7
Multiple Assignment
 Python allows us to assign a value to multiple variables in a single statement, which is also
known as multiple assignments.
 We can apply multiple assignments in two ways, either by assigning a single value to multiple
variables or assigning multiple values to multiple variables. Consider the following example.
 1. Assigning single value to multiple variables
x=y=z=1025
 2. Assigning multiple values to multiple variables
x,y,z =20, 30, 40
Here, The values will be assigned in the order in which variables appear.
8
Variable Types
 Local variables are the variables that declared inside the function and have scope within the
function.
 Global variables can be used throughout the program, and its scope is in the entire program.
We can use global variables inside or outside the function.
 A variable declared outside the function is the global variable by default. Python provides the
global keyword to use global variable inside the function. If we don't use the global keyword,
the function treats it as a local variable.
Local Variable
Variable
Global Variable
9
Example of local variable:
# Declaring a function
def add():
# Defining local variables. They has scope only within a function
a = 20
b = 30
c = a + b
print("The sum is:", c)
# Calling a function
add()
Note: If we try to use local variable outside the function, it will throw an error.
10
Example of global variable:
# Declare a variable and initialize it
x = 101
# Global variable in function
def mainFunction():
# printing a global variable
global x
print(x)
# modifying a global variable
x = 'Welcome To ISM'
print(x)
mainFunction()
print(x)
11
Deleting a Variable
 We can delete the variable using the del keyword. The syntax and example is given below.
del <variable_name>

More Related Content

What's hot

Operators in python
Operators in pythonOperators in python
Operators in python
Prabhakaran V M
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
Python Operators
Python OperatorsPython Operators
Python Operators
Adheetha O. V
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Dr.YNM
 

What's hot (20)

Operators in python
Operators in pythonOperators in python
Operators in python
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Strings in C
Strings in CStrings in C
Strings in C
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Python Operators
Python OperatorsPython Operators
Python Operators
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Python programming
Python  programmingPython  programming
Python programming
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 

Similar to Variables in python

Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
Ankita Shirke
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
manish kumar
 
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Class 8 - Java.pptx
Class 8 - Java.pptxClass 8 - Java.pptx
Class 8 - Java.pptx
sreedevi143432
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
Koteswari Kasireddy
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in javaShashwat Shriparv
 
Java Programming For Android
Java Programming For AndroidJava Programming For Android
Java Programming For Android
TechiNerd
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...
Core Java Programming Language (JSE) : Chapter III -  Identifiers, Keywords, ...Core Java Programming Language (JSE) : Chapter III -  Identifiers, Keywords, ...
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...
WebStackAcademy
 
1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf
Javier Crisostomo
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 

Similar to Variables in python (20)

Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Python basics
Python basicsPython basics
Python basics
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Class 8 - Java.pptx
Class 8 - Java.pptxClass 8 - Java.pptx
Class 8 - Java.pptx
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
Java Programming For Android
Java Programming For AndroidJava Programming For Android
Java Programming For Android
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...
Core Java Programming Language (JSE) : Chapter III -  Identifiers, Keywords, ...Core Java Programming Language (JSE) : Chapter III -  Identifiers, Keywords, ...
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...
 
1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 

More from Jaya Kumari

Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Jaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari
 
Oops
OopsOops
Inheritance
InheritanceInheritance
Inheritance
Jaya Kumari
 
Overloading
OverloadingOverloading
Overloading
Jaya Kumari
 
Decision statements
Decision statementsDecision statements
Decision statements
Jaya Kumari
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
Jaya Kumari
 
Looping statements
Looping statementsLooping statements
Looping statements
Jaya Kumari
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
Jaya Kumari
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya Kumari
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
Jaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
Jaya Kumari
 
Jsp basic
Jsp basicJsp basic
Jsp basic
Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
Jaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
Html form
Html formHtml form
Html form
Jaya Kumari
 

More from Jaya Kumari (20)

Python data type
Python data typePython data type
Python data type
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
Oops
OopsOops
Oops
 
Inheritance
InheritanceInheritance
Inheritance
 
Overloading
OverloadingOverloading
Overloading
 
Decision statements
Decision statementsDecision statements
Decision statements
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
Html form
Html formHtml form
Html form
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Variables in python

  • 1. Variables in Python Programming (Elective I) BCA - 105
  • 2. 2 What is Variable?  Variable is a name that is used to refer to memory location.  Python variable is also known as an identifier and used to hold value.  In Python, we don't need to specify the type of variable because Python is a infer language and smart enough to get variable type.  Variable names can be a group of both the letters and digits, but they have to begin with a letter or an underscore.  It is recommended to use lowercase letters for the variable name. For example, Rahul and rahul both are two different variables.
  • 3. 3 Declaring Variable and Assigning Values  Python does not bind us to declare a variable before using it in the application. It allows us to create a variable at the required time.  We don't need to declare explicitly variable in Python. When we assign any value to the variable, that variable is declared automatically.  The equal (=) operator is used to assign value to a variable.  In Python, variables are a symbolic name that is a reference or pointer to an object. The variables are used to denote objects by that name. Example: a=100 In the below image, the variable a refers to an integer object. a 100
  • 4. 4 Object Reference  It is necessary to understand how the Python interpreter works when we declare a variable. The process of treating variables is somewhat different from many other programming languages.  Python is the highly object-oriented programming language; that's why every data item belongs to a specific type of class. Consider the following example.  In the below example print statement, we have created a string object. type() is used to return the type of the object.
  • 5. 5 Object Identity  In Python, every created object identifies uniquely in Python.  Python provides the guaranteed that no two objects will have the same identifier.  The built-in id() function, is used to identify the object identifier.
  • 6. 6 How to define Variable Names  Variable names can be any length can have uppercase, lowercase (A to Z, a to z), the digit (0- 9), and underscore character(_). Consider the example of valid variables names. 1.name = "Devansh" 2.age = 20 3.marks = 80.50 1.name = "A" 2.Name = "B" 3.naMe = "C" 4.NAME = "D" 5.n_a_m_e = "E" 6._name = "F" 7.name_ = "G" 8._name_ = "H" 9.na56me = "I"  In the example, we have declared a few valid variable names such as name, _name_ , etc. But it is not recommended because when we try to read code, it may create confusion. The variable name should be descriptive to make code more readable.  The multi-word keywords can be created by the following method. 1. Camel Case - In the camel case, each word or abbreviation in the middle of begins with a capital letter. There is no intervention of whitespace. For example - nameOfStudent, valueOfVaraible, etc. 2. Pascal Case - It is the same as the Camel Case, but here the first word is also capital. For example - NameOfStudent, etc. 3. Snake Case - In the snake case, Words are separated by the underscore. For example - name_of_student, etc.
  • 7. 7 Multiple Assignment  Python allows us to assign a value to multiple variables in a single statement, which is also known as multiple assignments.  We can apply multiple assignments in two ways, either by assigning a single value to multiple variables or assigning multiple values to multiple variables. Consider the following example.  1. Assigning single value to multiple variables x=y=z=1025  2. Assigning multiple values to multiple variables x,y,z =20, 30, 40 Here, The values will be assigned in the order in which variables appear.
  • 8. 8 Variable Types  Local variables are the variables that declared inside the function and have scope within the function.  Global variables can be used throughout the program, and its scope is in the entire program. We can use global variables inside or outside the function.  A variable declared outside the function is the global variable by default. Python provides the global keyword to use global variable inside the function. If we don't use the global keyword, the function treats it as a local variable. Local Variable Variable Global Variable
  • 9. 9 Example of local variable: # Declaring a function def add(): # Defining local variables. They has scope only within a function a = 20 b = 30 c = a + b print("The sum is:", c) # Calling a function add() Note: If we try to use local variable outside the function, it will throw an error.
  • 10. 10 Example of global variable: # Declare a variable and initialize it x = 101 # Global variable in function def mainFunction(): # printing a global variable global x print(x) # modifying a global variable x = 'Welcome To ISM' print(x) mainFunction() print(x)
  • 11. 11 Deleting a Variable  We can delete the variable using the del keyword. The syntax and example is given below. del <variable_name>