PYTHON NOTES JEGAN K K
VARIABLE:
A variable in python can hold data of any data type (i.e. numeric / string / instances , etc).
Example:
a=3
b = 'pen'
v = Vector()
Declaring multiple variables in a single line requires map() function for scenarios where the
input is dynamically received from the user
Example: a, b = map (int, input().split())
Map() function used above, maps 2 integer values as input from the user, then assigns it to a, b
respectively.
We can also declare a variable with one value and multiple values on the same operation like
below,
a, *b = map (list, input().split())
Here '*' is used to assign series of remaining values to b.
LISTS:
In python, list is a collection of values of either same data type or different data types. List can
also be a collection of instances, lists, tuples, dictionaries, sets, etc.
To Declare an empty list [ ] (square brackets) are used ➔ a = [ ]
To receive dynamic input from user ➔ a = list (map(int, input().split()))
split() during input function, is used to split the input based on specified space value or the
whitespace on default.
INDEX:
To find an index of the value ➔ list-name . index (val)
The value is to be mentioned inside the curvy braces which inturn returns the index of that
mentioned value in the list.
Note: LIST index always starts from 0.
VARIABLE:
A variable in python can hold data of any data type (i.e. numeric / string / instances , etc).
Example:
a=3
b = 'pen'
v = Vector()
Declaring multiple variables in a single line requires map() function for scenarios where the
input is dynamically received from the user
Example: a, b = map (int, input().split())
Map() function used above, maps 2 integer values as input from the user, then assigns it to a, b
respectively.
We can also declare a variable with one value and multiple values on the same operation like
below,
a, *b = map (list, input().split())
Here '*' is used to assign series of remaining values to b.
LISTS:
In python, list is a collection of values of either same data type or different data types. List can
also be a collection of instances, lists, tuples, dictionaries, sets, etc.
To Declare an empty list [ ] (square brackets) are used ➔ a = [ ]
To receive dynamic input from user ➔ a = list (map(int, input().split()))
split() during input function, is used to split the input based on specified space value or the
whitespace on default.
INDEX:
To find an index of the value ➔ list-name . index (val)
The value is to be mentioned inside the curvy braces which inturn returns the index of that
mentioned value in the list.
Note: LIST index always starts from 0.