SSCS2051 – Programming
with Python
SSCS2051 – Programming
with Python
Python –Datatypes
Module-II
Python Data Types
Python Data Types
 Every value has a datatype, and variables can hold values.
 Python is a powerfully composed language; consequently, we don't
have to characterize the sort of variable while announcing it.
 The interpreter binds the value implicitly to its type.
 The Python interpreter will automatically interpret the variable as an
integer.
 We can verify the type of the program-used variable thanks to
Python. The type() function in Python returns the type of the passed
variable.
 Every value has a datatype, and variables can hold values.
 Python is a powerfully composed language; consequently, we don't
have to characterize the sort of variable while announcing it.
 The interpreter binds the value implicitly to its type.
 The Python interpreter will automatically interpret the variable as an
integer.
 We can verify the type of the program-used variable thanks to
Python. The type() function in Python returns the type of the passed
variable.
Python Data Types
Python Data Types
 Standard data types
 A variable can contain a variety of values. On the other hand,
a person's id must be stored as an integer, while their name
must be stored as a string.
 The storage method for each of the standard data types that
Python provides is specified by Python. The following is a list of
the Python-defined data types.
 Standard data types
 A variable can contain a variety of values. On the other hand,
a person's id must be stored as an integer, while their name
must be stored as a string.
 The storage method for each of the standard data types that
Python provides is specified by Python. The following is a list of
the Python-defined data types.
Python Data Types
Python Data Types
Python Data Types
Python Data Types
 Numbers :
 Numeric values are stored in numbers. The whole number,
float, and complex qualities have a place with a Python
Numbers datatype.
 Python offers the type() function to determine a variable's
data type. The instance () capability is utilized to check
whether an item has a place with a specific class.
 When a number is assigned to a variable, Python generates
Number objects. For instance,
 Numbers :
 Numeric values are stored in numbers. The whole number,
float, and complex qualities have a place with a Python
Numbers datatype.
 Python offers the type() function to determine a variable's
data type. The instance () capability is utilized to check
whether an item has a place with a specific class.
 When a number is assigned to a variable, Python generates
Number objects. For instance,
Python Data Types
Python Data Types
Python Data Types
Python Data Types
Python Data Types
Python Data Types
 Python supports three kinds of numerical data.
 Int: Whole number worth can be any length, like
numbers 10, 2, 29, - 20, - 150, and so on. An integer can
be any length you want in Python. Its worth has a place
with int.
 Float: Float stores drifting point numbers like 1.9, 9.902,
15.2, etc. It can be accurate to within 15 decimal
places.
 Complex: An intricate number contains an arranged
pair, i.e., x + iy, where x and y signify the genuine and
non-existent parts separately. The complex numbers like
2.14j, 2.0 + 2.3j, etc.
 Python supports three kinds of numerical data.
 Int: Whole number worth can be any length, like
numbers 10, 2, 29, - 20, - 150, and so on. An integer can
be any length you want in Python. Its worth has a place
with int.
 Float: Float stores drifting point numbers like 1.9, 9.902,
15.2, etc. It can be accurate to within 15 decimal
places.
 Complex: An intricate number contains an arranged
pair, i.e., x + iy, where x and y signify the genuine and
non-existent parts separately. The complex numbers like
2.14j, 2.0 + 2.3j, etc.
Sequence Type
Sequence Type
 String
 The sequence of characters in the quotation marks can be
used to describe the string. A string can be defined in Python
using single, double, or triple quotes.
 String dealing with Python is a direct undertaking since Python
gives worked-in capabilities and administrators to perform
tasks in the string.
 When dealing with strings, the operation "hello"+" python"
returns "hello python," and the operator + is used to combine
two strings.
 Because the operation "Python" *2 returns "Python Python" the
operator * is referred to as a repetition operator.
 The Python string is demonstrated in the following example.
 String
 The sequence of characters in the quotation marks can be
used to describe the string. A string can be defined in Python
using single, double, or triple quotes.
 String dealing with Python is a direct undertaking since Python
gives worked-in capabilities and administrators to perform
tasks in the string.
 When dealing with strings, the operation "hello"+" python"
returns "hello python," and the operator + is used to combine
two strings.
 Because the operation "Python" *2 returns "Python Python" the
operator * is referred to as a repetition operator.
 The Python string is demonstrated in the following example.
Sequence Type
Sequence Type
Sequence Type
Sequence Type
 Look at the following illustration of string handling.

 Look at the following illustration of string handling.

Sequence Type
Sequence Type
List
 Lists in Python are like arrays in C, but lists can
contain data of different types. The things put
away in the rundown are isolated with a comma (,)
and encased inside square sections [].
 To gain access to the list's data, we can use slice [:]
operators. Like how they worked with strings, the list
is handled by the concatenation operator (+) and
the repetition operator (*).
List
 Lists in Python are like arrays in C, but lists can
contain data of different types. The things put
away in the rundown are isolated with a comma (,)
and encased inside square sections [].
 To gain access to the list's data, we can use slice [:]
operators. Like how they worked with strings, the list
is handled by the concatenation operator (+) and
the repetition operator (*).
Sequence Type
Sequence Type
List

List

Sequence Type
Sequence Type


Sequence Type
Sequence Type
 Tuple
 In many ways, a tuple is like a list. Tuples, like
lists, also contain a collection of items from
various data types. A parenthetical space ()
separates the tuple's components from one
another.
Because we cannot alter the size or
value of the items in a tuple, it is a read-
only data structure.
 Tuple
 In many ways, a tuple is like a list. Tuples, like
lists, also contain a collection of items from
various data types. A parenthetical space ()
separates the tuple's components from one
another.
Because we cannot alter the size or
value of the items in a tuple, it is a read-
only data structure.
Sequence Type
Sequence Type
Sequence Type
Sequence Type
Sequence Type
Sequence Type
 Dictionary
 A dictionary is a key-value pair set arranged in any order. It
stores a specific value for each key, like an associative array or
a hash table. Value is any Python object, while the key can
hold any primitive data type.
 The comma (,) and the curly braces are used to separate the
items in the dictionary.
 Dictionary
 A dictionary is a key-value pair set arranged in any order. It
stores a specific value for each key, like an associative array or
a hash table. Value is any Python object, while the key can
hold any primitive data type.
 The comma (,) and the curly braces are used to separate the
items in the dictionary.
Sequence Type
Sequence Type
Boolean Type
Boolean Type
 True and False are the two default values for the Boolean type.
 These qualities are utilized to decide the given assertion valid
or misleading.
 The class book indicates this. False can be represented by the
0 or the letter "F," while true can be represented by any value
that is not zero.
 True and False are the two default values for the Boolean type.
 These qualities are utilized to decide the given assertion valid
or misleading.
 The class book indicates this. False can be represented by the
0 or the letter "F," while true can be represented by any value
that is not zero.
Boolean Type
Boolean Type
Sequence Type
Sequence Type
 Set
 The data type's unordered collection is Python Set. It is iterable,
mutable(can change after creation), and has remarkable
components.
 The elements of a set have no set order; It might return the
element's altered sequence.
 Either a sequence of elements is passed through the curly
braces and separated by a comma to create the set or the
built-in function set() is used to create the set.
 It can contain different kinds of values.
 Set
 The data type's unordered collection is Python Set. It is iterable,
mutable(can change after creation), and has remarkable
components.
 The elements of a set have no set order; It might return the
element's altered sequence.
 Either a sequence of elements is passed through the curly
braces and separated by a comma to create the set or the
built-in function set() is used to create the set.
 It can contain different kinds of values.
Sequence Type
Sequence Type
Sequence Type
Sequence Type
 List out difference between List and Tuple.
 List out difference between Set and Dictionary.
 List out difference between List and Tuple.
 List out difference between Set and Dictionary.
Python Variables
Python Variables
 A variable is the name given to a memory location. A value-
holding Python variable is also known as an identifier.
 Since Python is an infer language that is smart enough to
determine the type of a variable, we do not need to specify its
type in Python.
 Variable names must begin with a letter or an underscore, but
they can be a group of both letters and digits.
 The name of the variable should be written in lowercase. Both
Rahul and rahul are distinct variables.
 A variable is the name given to a memory location. A value-
holding Python variable is also known as an identifier.
 Since Python is an infer language that is smart enough to
determine the type of a variable, we do not need to specify its
type in Python.
 Variable names must begin with a letter or an underscore, but
they can be a group of both letters and digits.
 The name of the variable should be written in lowercase. Both
Rahul and rahul are distinct variables.
Python Variables
Python Variables
 Identifier Naming
 Identifiers are things like variables. An Identifier is utilized to
recognize the literals utilized in the program. The standards to
name an identifier are given underneath.
 Identifier Naming
 Identifiers are things like variables. An Identifier is utilized to
recognize the literals utilized in the program. The standards to
name an identifier are given underneath.
Python Variables
Python Variables
 The variable's first character must be an underscore or alphabet (_).
 Every one of the characters with the exception of the main person
might be a letter set of lower-case(a-z), capitalized (A-Z), highlight,
or digit (0-9).
 White space and special characters (!, @, #, %, etc.) are not
allowed in the identifier name. ^, &, *).
 Identifier name should not be like any watchword characterized in
the language.
 Names of identifiers are case-sensitive; for instance, my name, and
MyName isn't something very similar.
 Examples of valid identifiers: a123, _n, n_9, etc.
 Examples of invalid identifiers: 1a, n%4, n 9, etc.
 The variable's first character must be an underscore or alphabet (_).
 Every one of the characters with the exception of the main person
might be a letter set of lower-case(a-z), capitalized (A-Z), highlight,
or digit (0-9).
 White space and special characters (!, @, #, %, etc.) are not
allowed in the identifier name. ^, &, *).
 Identifier name should not be like any watchword characterized in
the language.
 Names of identifiers are case-sensitive; for instance, my name, and
MyName isn't something very similar.
 Examples of valid identifiers: a123, _n, n_9, etc.
 Examples of invalid identifiers: 1a, n%4, n 9, etc.
Python Variables
Python Variables
 Declaring Variable and Assigning Values
 Python doesn't tie us to pronounce a variable prior to involving it in
the application. It permits us to make a variable at the necessary
time.
 In Python, we don't have to explicitly declare variables. The variable
is declared automatically whenever a value is added to it.
 The equal (=) operator is utilized to assign worth to a variable.
 Declaring Variable and Assigning Values
 Python doesn't tie us to pronounce a variable prior to involving it in
the application. It permits us to make a variable at the necessary
time.
 In Python, we don't have to explicitly declare variables. The variable
is declared automatically whenever a value is added to it.
 The equal (=) operator is utilized to assign worth to a variable.
Python Variables
Python Variables
 Variable Names
 The process for declaring the valid variable has already been
discussed. Variable names can be any length can have capitalized,
lowercase (start to finish, a to z), the digit (0-9), and highlight
character(_). Take a look at the names of valid variables in the
following example.
 Variable Names
 The process for declaring the valid variable has already been
discussed. Variable names can be any length can have capitalized,
lowercase (start to finish, a to z), the digit (0-9), and highlight
character(_). Take a look at the names of valid variables in the
following example.
Python Variables
Python Variables
Python Variables
Python Variables
 The multi-word keywords can be created by the following method.
 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.
 Pascal Case - It is the same as the Camel Case, but here the first
word is also capital. For example - NameOfStudent, etc.
 Snake Case - In the snake case, Words are separated by the
underscore. For example - name_of_student, etc.
 The multi-word keywords can be created by the following method.
 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.
 Pascal Case - It is the same as the Camel Case, but here the first
word is also capital. For example - NameOfStudent, etc.
 Snake Case - In the snake case, Words are separated by the
underscore. For example - name_of_student, etc.
Python Variables
Python Variables
 Multiple Assignment
 Multiple assignments, also known as assigning values to multiple
variables in a single statement, is a feature of Python.
 We can apply different tasks in two ways, either by relegating a
solitary worth to various factors or doling out numerous qualities to
different factors. Take a look at the following example.
 Multiple Assignment
 Multiple assignments, also known as assigning values to multiple
variables in a single statement, is a feature of Python.
 We can apply different tasks in two ways, either by relegating a
solitary worth to various factors or doling out numerous qualities to
different factors. Take a look at the following example.
Python Variables
Python Variables
Python Variables
Python Variables
Python Variables
Python Variables
 There are two types of variables in Python - Local variable and
Global variable. Let's understand the following variables.
 Local Variable
 The variables that are declared within the function and have
scope within the function are known as local variables. Let's
examine the following illustration.
 There are two types of variables in Python - Local variable and
Global variable. Let's understand the following variables.
 Local Variable
 The variables that are declared within the function and have
scope within the function are known as local variables. Let's
examine the following illustration.
Python Variables
Python Variables
Python Variables
Python Variables
 We declared the function add() and assigned a few
variables to it in the code above. These factors will be
alluded to as the neighborhood factors which have
scope just inside the capability. We get the error that
follows if we attempt to use them outside of the function.
 We declared the function add() and assigned a few
variables to it in the code above. These factors will be
alluded to as the neighborhood factors which have
scope just inside the capability. We get the error that
follows if we attempt to use them outside of the function.
Python Variables
Python Variables
 Global Variables
 Global variables can be utilized all through the
program, and its extension is in the whole program.
Global variables can be used inside or outside the
function.
 By default, a variable declared outside of the
function serves as the global variable. Python gives
the worldwide catchphrase to utilize worldwide
variable inside the capability. The function treats it
as a local variable if we don't use the global
keyword. Let's examine the following illustration.
 Global Variables
 Global variables can be utilized all through the
program, and its extension is in the whole program.
Global variables can be used inside or outside the
function.
 By default, a variable declared outside of the
function serves as the global variable. Python gives
the worldwide catchphrase to utilize worldwide
variable inside the capability. The function treats it
as a local variable if we don't use the global
keyword. Let's examine the following illustration.
Python Variables
Python Variables
Python Variables
Python Variables
In the above code, we declare a global
variable x and give out a value to it. We
then created a function and used the
global keyword to access the declared
variable within the function. We can
now alter its value. After that, we gave
the variable x a new string value and
then called the function and printed x,
which displayed the new value.
In the above code, we declare a global
variable x and give out a value to it. We
then created a function and used the
global keyword to access the declared
variable within the function. We can
now alter its value. After that, we gave
the variable x a new string value and
then called the function and printed x,
which displayed the new value.
Python Variables
Python Variables
 Delete a variable
 We can delete the variable using the del keyword. The
syntax is given below.
 Syntax -
 del <variable_name>
 In the following example, we create a variable x and
assign value to it. We deleted variable x, and print it, we
get the error "variable x is not defined". The variable x will
no longer use in future.
 Delete a variable
 We can delete the variable using the del keyword. The
syntax is given below.
 Syntax -
 del <variable_name>
 In the following example, we create a variable x and
assign value to it. We deleted variable x, and print it, we
get the error "variable x is not defined". The variable x will
no longer use in future.
Python Variables
Python Variables
Next Module III
Next Module III
 Python Program Flow Control.
 Python Program Flow Control.

E-Notes_3720_Content_Document_20250107032323PM.pdf

  • 1.
    SSCS2051 – Programming withPython SSCS2051 – Programming with Python Python –Datatypes Module-II
  • 2.
    Python Data Types PythonData Types  Every value has a datatype, and variables can hold values.  Python is a powerfully composed language; consequently, we don't have to characterize the sort of variable while announcing it.  The interpreter binds the value implicitly to its type.  The Python interpreter will automatically interpret the variable as an integer.  We can verify the type of the program-used variable thanks to Python. The type() function in Python returns the type of the passed variable.  Every value has a datatype, and variables can hold values.  Python is a powerfully composed language; consequently, we don't have to characterize the sort of variable while announcing it.  The interpreter binds the value implicitly to its type.  The Python interpreter will automatically interpret the variable as an integer.  We can verify the type of the program-used variable thanks to Python. The type() function in Python returns the type of the passed variable.
  • 3.
    Python Data Types PythonData Types  Standard data types  A variable can contain a variety of values. On the other hand, a person's id must be stored as an integer, while their name must be stored as a string.  The storage method for each of the standard data types that Python provides is specified by Python. The following is a list of the Python-defined data types.  Standard data types  A variable can contain a variety of values. On the other hand, a person's id must be stored as an integer, while their name must be stored as a string.  The storage method for each of the standard data types that Python provides is specified by Python. The following is a list of the Python-defined data types.
  • 4.
  • 5.
    Python Data Types PythonData Types  Numbers :  Numeric values are stored in numbers. The whole number, float, and complex qualities have a place with a Python Numbers datatype.  Python offers the type() function to determine a variable's data type. The instance () capability is utilized to check whether an item has a place with a specific class.  When a number is assigned to a variable, Python generates Number objects. For instance,  Numbers :  Numeric values are stored in numbers. The whole number, float, and complex qualities have a place with a Python Numbers datatype.  Python offers the type() function to determine a variable's data type. The instance () capability is utilized to check whether an item has a place with a specific class.  When a number is assigned to a variable, Python generates Number objects. For instance,
  • 6.
  • 7.
  • 8.
    Python Data Types PythonData Types  Python supports three kinds of numerical data.  Int: Whole number worth can be any length, like numbers 10, 2, 29, - 20, - 150, and so on. An integer can be any length you want in Python. Its worth has a place with int.  Float: Float stores drifting point numbers like 1.9, 9.902, 15.2, etc. It can be accurate to within 15 decimal places.  Complex: An intricate number contains an arranged pair, i.e., x + iy, where x and y signify the genuine and non-existent parts separately. The complex numbers like 2.14j, 2.0 + 2.3j, etc.  Python supports three kinds of numerical data.  Int: Whole number worth can be any length, like numbers 10, 2, 29, - 20, - 150, and so on. An integer can be any length you want in Python. Its worth has a place with int.  Float: Float stores drifting point numbers like 1.9, 9.902, 15.2, etc. It can be accurate to within 15 decimal places.  Complex: An intricate number contains an arranged pair, i.e., x + iy, where x and y signify the genuine and non-existent parts separately. The complex numbers like 2.14j, 2.0 + 2.3j, etc.
  • 9.
    Sequence Type Sequence Type String  The sequence of characters in the quotation marks can be used to describe the string. A string can be defined in Python using single, double, or triple quotes.  String dealing with Python is a direct undertaking since Python gives worked-in capabilities and administrators to perform tasks in the string.  When dealing with strings, the operation "hello"+" python" returns "hello python," and the operator + is used to combine two strings.  Because the operation "Python" *2 returns "Python Python" the operator * is referred to as a repetition operator.  The Python string is demonstrated in the following example.  String  The sequence of characters in the quotation marks can be used to describe the string. A string can be defined in Python using single, double, or triple quotes.  String dealing with Python is a direct undertaking since Python gives worked-in capabilities and administrators to perform tasks in the string.  When dealing with strings, the operation "hello"+" python" returns "hello python," and the operator + is used to combine two strings.  Because the operation "Python" *2 returns "Python Python" the operator * is referred to as a repetition operator.  The Python string is demonstrated in the following example.
  • 10.
  • 11.
    Sequence Type Sequence Type Look at the following illustration of string handling.   Look at the following illustration of string handling. 
  • 12.
    Sequence Type Sequence Type List Lists in Python are like arrays in C, but lists can contain data of different types. The things put away in the rundown are isolated with a comma (,) and encased inside square sections [].  To gain access to the list's data, we can use slice [:] operators. Like how they worked with strings, the list is handled by the concatenation operator (+) and the repetition operator (*). List  Lists in Python are like arrays in C, but lists can contain data of different types. The things put away in the rundown are isolated with a comma (,) and encased inside square sections [].  To gain access to the list's data, we can use slice [:] operators. Like how they worked with strings, the list is handled by the concatenation operator (+) and the repetition operator (*).
  • 13.
  • 14.
  • 15.
    Sequence Type Sequence Type Tuple  In many ways, a tuple is like a list. Tuples, like lists, also contain a collection of items from various data types. A parenthetical space () separates the tuple's components from one another. Because we cannot alter the size or value of the items in a tuple, it is a read- only data structure.  Tuple  In many ways, a tuple is like a list. Tuples, like lists, also contain a collection of items from various data types. A parenthetical space () separates the tuple's components from one another. Because we cannot alter the size or value of the items in a tuple, it is a read- only data structure.
  • 16.
  • 17.
  • 18.
    Sequence Type Sequence Type Dictionary  A dictionary is a key-value pair set arranged in any order. It stores a specific value for each key, like an associative array or a hash table. Value is any Python object, while the key can hold any primitive data type.  The comma (,) and the curly braces are used to separate the items in the dictionary.  Dictionary  A dictionary is a key-value pair set arranged in any order. It stores a specific value for each key, like an associative array or a hash table. Value is any Python object, while the key can hold any primitive data type.  The comma (,) and the curly braces are used to separate the items in the dictionary.
  • 19.
  • 20.
    Boolean Type Boolean Type True and False are the two default values for the Boolean type.  These qualities are utilized to decide the given assertion valid or misleading.  The class book indicates this. False can be represented by the 0 or the letter "F," while true can be represented by any value that is not zero.  True and False are the two default values for the Boolean type.  These qualities are utilized to decide the given assertion valid or misleading.  The class book indicates this. False can be represented by the 0 or the letter "F," while true can be represented by any value that is not zero.
  • 21.
  • 22.
    Sequence Type Sequence Type Set  The data type's unordered collection is Python Set. It is iterable, mutable(can change after creation), and has remarkable components.  The elements of a set have no set order; It might return the element's altered sequence.  Either a sequence of elements is passed through the curly braces and separated by a comma to create the set or the built-in function set() is used to create the set.  It can contain different kinds of values.  Set  The data type's unordered collection is Python Set. It is iterable, mutable(can change after creation), and has remarkable components.  The elements of a set have no set order; It might return the element's altered sequence.  Either a sequence of elements is passed through the curly braces and separated by a comma to create the set or the built-in function set() is used to create the set.  It can contain different kinds of values.
  • 23.
  • 24.
    Sequence Type Sequence Type List out difference between List and Tuple.  List out difference between Set and Dictionary.  List out difference between List and Tuple.  List out difference between Set and Dictionary.
  • 25.
    Python Variables Python Variables A variable is the name given to a memory location. A value- holding Python variable is also known as an identifier.  Since Python is an infer language that is smart enough to determine the type of a variable, we do not need to specify its type in Python.  Variable names must begin with a letter or an underscore, but they can be a group of both letters and digits.  The name of the variable should be written in lowercase. Both Rahul and rahul are distinct variables.  A variable is the name given to a memory location. A value- holding Python variable is also known as an identifier.  Since Python is an infer language that is smart enough to determine the type of a variable, we do not need to specify its type in Python.  Variable names must begin with a letter or an underscore, but they can be a group of both letters and digits.  The name of the variable should be written in lowercase. Both Rahul and rahul are distinct variables.
  • 26.
    Python Variables Python Variables Identifier Naming  Identifiers are things like variables. An Identifier is utilized to recognize the literals utilized in the program. The standards to name an identifier are given underneath.  Identifier Naming  Identifiers are things like variables. An Identifier is utilized to recognize the literals utilized in the program. The standards to name an identifier are given underneath.
  • 27.
    Python Variables Python Variables The variable's first character must be an underscore or alphabet (_).  Every one of the characters with the exception of the main person might be a letter set of lower-case(a-z), capitalized (A-Z), highlight, or digit (0-9).  White space and special characters (!, @, #, %, etc.) are not allowed in the identifier name. ^, &, *).  Identifier name should not be like any watchword characterized in the language.  Names of identifiers are case-sensitive; for instance, my name, and MyName isn't something very similar.  Examples of valid identifiers: a123, _n, n_9, etc.  Examples of invalid identifiers: 1a, n%4, n 9, etc.  The variable's first character must be an underscore or alphabet (_).  Every one of the characters with the exception of the main person might be a letter set of lower-case(a-z), capitalized (A-Z), highlight, or digit (0-9).  White space and special characters (!, @, #, %, etc.) are not allowed in the identifier name. ^, &, *).  Identifier name should not be like any watchword characterized in the language.  Names of identifiers are case-sensitive; for instance, my name, and MyName isn't something very similar.  Examples of valid identifiers: a123, _n, n_9, etc.  Examples of invalid identifiers: 1a, n%4, n 9, etc.
  • 28.
    Python Variables Python Variables Declaring Variable and Assigning Values  Python doesn't tie us to pronounce a variable prior to involving it in the application. It permits us to make a variable at the necessary time.  In Python, we don't have to explicitly declare variables. The variable is declared automatically whenever a value is added to it.  The equal (=) operator is utilized to assign worth to a variable.  Declaring Variable and Assigning Values  Python doesn't tie us to pronounce a variable prior to involving it in the application. It permits us to make a variable at the necessary time.  In Python, we don't have to explicitly declare variables. The variable is declared automatically whenever a value is added to it.  The equal (=) operator is utilized to assign worth to a variable.
  • 29.
    Python Variables Python Variables Variable Names  The process for declaring the valid variable has already been discussed. Variable names can be any length can have capitalized, lowercase (start to finish, a to z), the digit (0-9), and highlight character(_). Take a look at the names of valid variables in the following example.  Variable Names  The process for declaring the valid variable has already been discussed. Variable names can be any length can have capitalized, lowercase (start to finish, a to z), the digit (0-9), and highlight character(_). Take a look at the names of valid variables in the following example.
  • 30.
  • 31.
    Python Variables Python Variables The multi-word keywords can be created by the following method.  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.  Pascal Case - It is the same as the Camel Case, but here the first word is also capital. For example - NameOfStudent, etc.  Snake Case - In the snake case, Words are separated by the underscore. For example - name_of_student, etc.  The multi-word keywords can be created by the following method.  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.  Pascal Case - It is the same as the Camel Case, but here the first word is also capital. For example - NameOfStudent, etc.  Snake Case - In the snake case, Words are separated by the underscore. For example - name_of_student, etc.
  • 32.
    Python Variables Python Variables Multiple Assignment  Multiple assignments, also known as assigning values to multiple variables in a single statement, is a feature of Python.  We can apply different tasks in two ways, either by relegating a solitary worth to various factors or doling out numerous qualities to different factors. Take a look at the following example.  Multiple Assignment  Multiple assignments, also known as assigning values to multiple variables in a single statement, is a feature of Python.  We can apply different tasks in two ways, either by relegating a solitary worth to various factors or doling out numerous qualities to different factors. Take a look at the following example.
  • 33.
  • 34.
  • 35.
    Python Variables Python Variables There are two types of variables in Python - Local variable and Global variable. Let's understand the following variables.  Local Variable  The variables that are declared within the function and have scope within the function are known as local variables. Let's examine the following illustration.  There are two types of variables in Python - Local variable and Global variable. Let's understand the following variables.  Local Variable  The variables that are declared within the function and have scope within the function are known as local variables. Let's examine the following illustration.
  • 36.
  • 37.
    Python Variables Python Variables We declared the function add() and assigned a few variables to it in the code above. These factors will be alluded to as the neighborhood factors which have scope just inside the capability. We get the error that follows if we attempt to use them outside of the function.  We declared the function add() and assigned a few variables to it in the code above. These factors will be alluded to as the neighborhood factors which have scope just inside the capability. We get the error that follows if we attempt to use them outside of the function.
  • 38.
    Python Variables Python Variables Global Variables  Global variables can be utilized all through the program, and its extension is in the whole program. Global variables can be used inside or outside the function.  By default, a variable declared outside of the function serves as the global variable. Python gives the worldwide catchphrase to utilize worldwide variable inside the capability. The function treats it as a local variable if we don't use the global keyword. Let's examine the following illustration.  Global Variables  Global variables can be utilized all through the program, and its extension is in the whole program. Global variables can be used inside or outside the function.  By default, a variable declared outside of the function serves as the global variable. Python gives the worldwide catchphrase to utilize worldwide variable inside the capability. The function treats it as a local variable if we don't use the global keyword. Let's examine the following illustration.
  • 39.
  • 40.
    Python Variables Python Variables Inthe above code, we declare a global variable x and give out a value to it. We then created a function and used the global keyword to access the declared variable within the function. We can now alter its value. After that, we gave the variable x a new string value and then called the function and printed x, which displayed the new value. In the above code, we declare a global variable x and give out a value to it. We then created a function and used the global keyword to access the declared variable within the function. We can now alter its value. After that, we gave the variable x a new string value and then called the function and printed x, which displayed the new value.
  • 41.
    Python Variables Python Variables Delete a variable  We can delete the variable using the del keyword. The syntax is given below.  Syntax -  del <variable_name>  In the following example, we create a variable x and assign value to it. We deleted variable x, and print it, we get the error "variable x is not defined". The variable x will no longer use in future.  Delete a variable  We can delete the variable using the del keyword. The syntax is given below.  Syntax -  del <variable_name>  In the following example, we create a variable x and assign value to it. We deleted variable x, and print it, we get the error "variable x is not defined". The variable x will no longer use in future.
  • 42.
  • 43.
    Next Module III NextModule III  Python Program Flow Control.  Python Program Flow Control.