You are on page 1of 3

PYTHON DATA TYPES

User defined functions:

1) string = [ ‘abcg’, ‘eff’, ‘hijd’, ‘lmi’ ]

def func1(1) :
return 1(-1) //-1 is the index value
func1(string)

o/p: lmi(-1 indicates the last element in the list)

2) string = [ ‘abcg’, ‘hijd’, ‘eff’, ‘lmi’ ]

print(func1(‘abcg’)

o/p:g //func1 means return1(-1);(abcg(-1))=g;last element n the variable

3) Print(sorted(string,key=func1))

o/p: [ ‘hijd’, ‘eff’, ’abcg’, ‘lmi’] //abcg(-1)=g; hijd(-1)=d; eff(-1)=f; lmi(-1)=i


//g,d,f,i~d,f,g,i

TUPLES

 Enclosed in parenthesis() //list square brackets[]


 Immutable(not able to change) //list(mutable-changeable)

Benefits:
 Faster than list
 Used as a keys in dictionaries //list can’t
tup1 = (1,2,3,4,5,6,7)
print(tup1[1:5])

o/p: (2,3,4,5) //index of last element is ‘0’ or ignored

SETS:
1. Store multiple items in the single variable.
 Unindexed
 Unordered
 Mutable
 Do not allow duplicates
 Frozen sets are immutable
2.Enclosed in ([]) //list[]
//tuples()

MAPPING/DICTIONARIES

 Unordered
 Keys immutable & the values are mutable
 {} //list[] ; tuple(); sets[()]; dictionaries{}

STRINGS
 Letters,numbers,special characters
 (‘abc’) or (“abc”) or (“””abc”””)
 Strings immutable
 Indexing and slicing operators.
 Positive index starts from ‘0’and negative index ‘-1’ helps in accessing from the end.
DISTANCE METHOD/EUCLIDEAN DISTANCE (refer note for examples)

 It is a distance measure that best can be explained as the length of a segment
connecting two points.

The formula is rather straightforward as the distance is calculated from the


cartesian coordinates of the points using the Pythagorean theorem.

LOOPS
 Repeated set of instructions.
TYPES
 For loop
 While loop
 Nested loop
How to control loops or control statement in python?
 Continue statement
 Break statement
 Pass statement

You might also like