PTHYON NOTES
Lecture 1
Input\output, Variables and data types:
Interpreter is used in python while compilers are used in other languages
Variable: it is a name given to a memory location in a program
Rules for identifiers (variable names)
1 Start with upper or lower case letters
2 Don’t start with digits
3 we can’t use special characters in identifiers
4 identifiers can be of any length.
Data types
Integers
Float
Boolean
String
None
Types of operations
Arithmetic operations
Rational or comparison operations
Assignment operations
Logical operations
Lecture 2
Strings and conditional statements
String is a data type that store a sequence of characters
Concatenation is an adding two or more strings like “hello” + “world” “hello world”
Length of string: len(str) is function to find the length of string
Indexing indexing is basically the position of character in string
Slicing: accessing part of string
Functions in python
Lecture 3 lists and tuple in python
List is a built-in data type that stores set of values
(integers,float,strings etc)
In python we can store different data types in list..i.e int str and float etc
In python strings are immutable while the lists are mutable
Slicing is also possible in list like strings but that should be in range
Negative slicing is Also possible in lists the last value should be -1
List methods or list functions
[Link]() it means that add value in the end if we have 3 values in the list then we add the 4 th
one by [Link](4).
[Link]() this function will sort list in ascending order
List can also be sorted in descending order by [Link](reverse=true)
[Link]() can reverse the whole list
[Link](inx,vl) insert value at certain index. In this function 1st we will put the index nbr where we
want to insert value and the value
[Link]() this function can remove the 1st occurrence value from the list
[Link](indx) this function will remove element at index
Tuples
Tuples are built in data type that lets us create immutable sequence of values
In tuples we use parenthesis instead of square bracket
We can also access any value in tuple but not change the value like in list
Slicing is also possible in tuple
Tuples methods or tuple functions
[Link](el) this function will tell us the location of element in tuple
[Link](el) this function will count the total occurrence of that number
Dictionaries and sets:
These are very important data structures.
Dictionaries are used to store data values in key:value pairs
They are unordered mutuable and don’t allow duplicate keys
Nested dictionary: we can also use nested dictionary like nested conditional statement
Dictionary methods/functions
[Link]() it will return all keys
[Link]() it will return all values
[Link]() it will return all(key,values) as tuples
[Link](“key”) it will return key according to value
[Link](newDict) insert the specified items to the dictionary
sets:
sets are the collection of unordered items
we can store any data type in set
if there is more than 2 values they will print only 1 time
empty set: should be created as set()
loops in python while and for loop
loops are used to repeat instructions
Functions and recursions
Block of statement that used to perform a specific task