Professional Documents
Culture Documents
Python Learning
Python Learning
To enter into a sub directory type cd<space>name of the directory it will take you into that directory
__________________________________________________________________________________
Typically indexing is used when we ned to return a single character - in index [ ] are used and each
character returns a specific index value eg :
Character : h e l l o
Reverse : 0 -4-3-2-1 it can be used when we don’t know the length of the character but we want
to obtain the last or penultimate chars.
Slicing : - typically used to grab a subsection of a string so typically used in returning more than one
character . the syntax for slicing is as follows [start:stop:step]
Where start is the starting index value i.e from which char u want to start grabbing
Stop is slightly different stop is the index value of the char until which u wanto grab but not including
that char so the o/p gives char from starting index to the one just before the stoping index.
Then there is the 3rd parameter step . it specifies how much jump it should make to get the next
character.. [ : : 2] implies give o/p as after 1st char jump to the 2nd char after the first then again to
the 2nd after that
In python strings cnnot be reassigned using indexes for eg : if name = ‘sam’ and we want to change it
to ‘pam’ we need to change s to p only ,so if we think name[0]=’p’ that is change the value of string
at index 0 in name to ‘p’ ..it will only give an error not the result pam.some other functions can give
you character reassignment which we will look into later.
Python has Dynamic typing variables compared to some other languages such as c or c++ which has
Static Typing Variables .. this means that when a variable is assingned a value for eg : a=2 in python
later in code the integer type value can be changed and given another data type value like a list for
eg : a = [“cricket”,”football”] and the python code will not show any error …but in case of lamguages
like c we first assign the variable to be an int datatype eg : int a=2 … so the value cannot be later
changed in the code .
There are pros and cons to Dynamic typing : pros – makes it easy to work with and becomes easy to
read the code …cons – can produce bugs since different data types are in play .so should be aware of
the types() in python.
TOPICS – PYTHON
**** NUMBERS****
int (for integer)
float
str (for string)
list
tuple
dict (for dictionary)
set
bool (for Boolean True/False)